Saturday, June 16, 2007

Hello World with Silverlight

OK, let's begin with the hello world! :)
All we need to do (after installing the Silverlight tools for Orcas and Silverlight 1.1 Alpha) is to create a new project "C# -> Silverlight project".
The project template will create for us several files:

1. Page.xaml
1.1. Page.xaml.cs
2. Silverlight.js
3. TestPage.html
3.1. TestPage.html.js

The first one - Silverlight.js is Javascript required for the silverlight client.
Page.xaml is the Silverlight canvas itself - the project that we will work with.
TestPage.html is the HTML client page that will host our Silverlight control.

Let's go deep into it.
The Page.xaml. XAML stands for eXtensible Application Markup Language, and is pronounced "Zammel", was introduced with Microsoft.NET Framework 3.0 as the User Interface definition language for the next generation of applications. It is a normal XML file, and can be edited with any text-editing tool (we will use better than text editing). The empty project file will look like this:

That's right - we have Page.xaml.cs and this is the "code-behind" file.

Well, we can simply add one TextBlock element to this canvas:

^textblock color="#cc0000">Text="Hello World" FontSize="15" FontWeight="Bold" />

So at finally we have the following XAML code:

See you later on.

No comments: