Silverlight: Hello, World!

Software

OK – I bought the books, I downloaded the required code, I’m ready to go. First Silverlight compile time! What can I say – I’m a big fan of “Hello, World!” functionality.

The first thing I notice is that there are two new Silverlight project types: Silverlight Project and Silverlight Class Library. From what I’ve gathered thus far, these are roughly analogous to the .NET 2.0-era ASP.NET Web Project (or Website) and Class Library project types. I’m not yet sure why Silverlight has it’s own Class Library type — could be a templated version of the normal class library, or perhaps this is meant to run on the client?

I start a new Silverlight Project and build it with no problems. Running it produces a blank page, which is expected. OK – let’s get to the Hello, World stuff! How do I create a static label?

Turning to the Page.xaml file, I see the following definition:

<Canvas x:Name="parentCanvas"
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Loaded="Page_Loaded"
x:Class="SilverlightProject1.Page;assembly=ClientBin/SilverlightProject1.dll"
Width="640"
Height="480"
Background="White"
>
</Canvas>

Which looks like a good place to start. First thing I notice here is that the default output directory for the build artifacts has moved to /ClientBin/, instead of /bin/. I’m pretty sure this must be a client-side output directory. Next thing I see is that there’s a hook into a DLL, also presumably client-side, with the fully qualified namespace of the class referenced. I interpret this to be sort of like the code-behind file for this XAML. Third thing I see is that Silverlight pages (if that’s the right term) are size-specific; we’ll probably get into that later.

So – the label. It takes no more than a few seconds of Google searching before I find the answer: use a <TextBlock> control. Aptly named, says me! The text you want to display goes in the … drum roll please … Text property.

<Canvas .... >
<TextBlock Text="Hello, World!">
</Canvas>

And with tonight’s job wrapped up, I close this post. More to come later.

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Furl
  • Ma.gnolia
  • Reddit
  • TwitThis
1 Comment

No Comments

1 Trackback

Leave a Reply

Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">