Adventures with Silverlight

I’ve started on the path to Silver(en)light(enment). I thought I use the blog as way of recording any gotcha’s or interesting facts.
 
Installation – The links to the Silverlight runtime didn’t work so I had to grab that from http://www.microsoft.com/silverlight/downloads.aspx
 
Once installed I went straight for the Chess sample. Watched .net murder javascript at chess, then watched it murder me at chess. I must try and play Javascript 😉
 
Onto the quickstart materials. First off you have to go through a brief manual installation involving setting up a web site. Then you’re off and running.
 
Interesting points
#1. Silverlight consumes unhandled exceptions. Anyone used to to writing .net application will, I’m sure, have see the unhandled exception dialog. Well true to form pretty much my first line of code had an error, I’d put the name of my textbox onto the canvas element rather than the "TextBlock" (why the change in name?). The code ran without any errors. So I put catch all thrown exceptions on in the debugger and there it was, "cannot cast" exception. That could have caught me out if I’d been a bit further down the code than the first event handler!
 
#2. Auto wiring up of names to fields. If you provide an XAML element with a "Name" then you can access that element via FindName and the like. However, if you try to use it directly "MyElement.Text=…" then you’ll get a compile error. The trick is to use "x:Name=…" this automatically create a field for the element in the code-behind.
 
 
 
 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s