SilverLife 2.0

Silverlight 2.0 Beta 1 shipped yesterday, so I thought now would be a good time to deploy a new version of SilverLife. SilverLife is a Silverlight implementation of John Conway’s game of Life. Version 1.0, which I published in August of last year, targeted the Silverlight 1.1 alpha. Version 2.0 targets the new Silverlight 2.0 beta and can be viewed at https://training.atmosera.com/silverlife. You can download the source code from training.atmosera.com/downloads/silverlife_2.0.zip.

SilverLife 2.0 looks almost exactly like version 1.0, save for the buttons at the bottom of the grid. Silverlight 1.1 had no controls built in, so I had to manufacture something that looked like buttons. Silverlight 2.0 Beta 1 contains more than 20 built-in control types, so I used Button controls. I also took advantage of the new style support in Silverlight 2.0 to stylize the buttons. First I defined a style named “LifeButton” in XAML:

 

 

 

<Style x_Key=”LifeButton” TargetType=”Button”>

  <Setter Property=”Width” Value=”132″ />

  <Setter Property=”Height” Value=”44″ />

  <Setter Property=”FontSize” Value=”16″ />

</Style>

 

Then I applied the style to the four Button controls:

 

<Button x_Name=”StartButton” Style=”{StaticResource LifeButton}” … />

<Button x_Name=”StopButton” Style=”{StaticResource LifeButton}” … />

<Button x_Name=”StepButton” Style=”{StaticResource LifeButton}” … />

<Button x_Name=”ClearButton” Style=”{StaticResource LifeButton}” … />

 

This is an extremely simple example, but styles can be much more complex and can even use templates to completely redefine a control’s visual tree. Styles and templates are going to be incredibly important to Silverlight 2.0 apps, so I’ll be writing more about them later.

Porting SilverLife from Silverlight 1.1 to 2.0 required just a handful of changes. First I used Visual Studio 2008 to create a new Silverlight project. Then I imported most of the code and XAML from the first version of SilverLife and began patching things up. Here are some of the changes that were required:

  • The XamlReader class moved to the System.Windows.Markup namespace
  • XamlReader.Load now requires an http://schemas.microsoft.com/client/2007″>http://schemas.microsoft.com/client/2007” attribute
  • HtmlPage.Document.GetElementByID changed to HtmlPage.Document.GetElementById
  • The IsolatedStorageFileStream constructor now throws an IsolatedStorageException rather than an IOException if you attempt to open a file that doesn’t exist

One of the most pleasant surprises in Silverlight 2.0 Beta 1 is the simplified deployment strategy. XAML files and other resources (for example, images) are now compiled into the application’s assembly. Moreover, the assembly and any assemblies it depends upon are packaged in a XAP file, which is a glorified zip file containing a manifest. The upshot is that deploying the application to Wintellect’s Web server required two simple steps:

  • Copy Default.html (the page that hosts the application) into the Silverlife directory
  • Create a ClientBin folder in that directory and copy Silverlife.xap into it

That’s it! Other than adding a new MIME type (“application/x-silverlight-app”) to IIS and mapping it to XAP files (a one-time procedure), deployment involved nothing more copying a couple of files. How cool is that?

Another pleasant surprise was the fact that Silverlight 2.0 displays a default progress UI as the XAP file is downloaded. Now users won’t have to stare at a blank canvas as they wait for assemblies to be downloaded. Nor will you, the developer, have to code up a progress UI.

I’ll have much, much more to say in future posts. A new day is dawning, and it has Silverlight 2.0 written all over it!

Jeff Prosise

View Comments

  • I think my book-writing days are over, John. But I appreciate the thought. :-)
    I do have a novel in mind that I may try to write someday. I wonder if a geek author can become a fiction author?

  • Is it supposed to do something? I am just staring at it waiting for something to happen after hitting "Start"...

  • Nikola, I have the same problem. Some Silverlight 2 Beta 1 apps on the Web like Jeff's just don't display anything at all. Is this a bug in the runtime?

  • I investigated a little, and I think I know why SilverLife works to some, and doesn't to others. There is a bug in Silverlite beta 1 that is manifested only when in Regional options in Windows settings decimal symbol is comma (,) and not a dot (.)!
    However, program will work if in constructor in file Page.xaml.cs expression
    Rectangle rect = (Rectangle)XamlReader.Load(String.Format(_rect, x + 1, y + 1, _width - _spacing, _height - _spacing, _opacity));
    is replaced with
    Rectangle rect = (Rectangle)XamlReader.Load(String.Format(_rect, x + 1, y + 1, _width - _spacing, _height - _spacing, _opacity.ToString().Replace(',', '.')));
    This bug is left over from alpha version of Silverlight 1.1 and as far as I can see it is still not rectified.
    I hope that this will be settled in final version as in many countries decimal symbol is comma.

Recent Posts

8-Step AWS to Microsoft Azure Migration Strategy

Microsoft Azure and Amazon Web Services (AWS) are two of the most popular cloud platforms.…

5 days ago

How to Navigate Azure Governance

 Cloud management is difficult to do manually, especially if you work with multiple cloud…

2 weeks ago

Why Azure’s Scalability is Your Key to Business Growth & Efficiency

Azure’s scalable infrastructure is often cited as one of the primary reasons why it's the…

4 weeks ago

Unlocking the Power of AI in your Software Development Life Cycle (SDLC)

https://www.youtube.com/watch?v=wDzCN0d8SeA Watch our "Unlocking the Power of AI in your Software Development Life Cycle (SDLC)"…

1 month ago

The Role of FinOps in Accelerating Business Innovation

FinOps is a strategic approach to managing cloud costs. It combines financial management best practices…

1 month ago

Azure Kubernetes Security Best Practices

Using Kubernetes with Azure combines the power of Kubernetes container orchestration and the cloud capabilities…

2 months ago