Tuesday, February 17, 2009

Random hints and tips on Silverlight

Lately I ran into a few quirks while doing some prototyping in Silverlight and I taught it would be nice to share them with you people.

Silverlight Application Name
Actually this is more about the name of the website that VS2008 creates for you when you create a Silverlight application. If the name of the Silverlight application is relatively long, it may very well result in a to long name for your ASP.NET website. This will result in an error as that project is created.

IntelliSense with Silverlight assemblies
If you use a Silverlight class library to build some usercontrol in and you reference it in a Silverlight application, IntelliSense will not show the class while your typing your namespace alias declaration in xaml. You have to compile the class library before it shows up.

Getting a template applied on your custom control
This may seem obvious, but it had me struggling for quite a bit. Whenever you added a template in generic.xaml to apply it to some custom control it is important to know it has to go into a folder called themes. Otherwise the template won't be found. This is only since release and is not well documented.

Refactoring doesn't effect XAML
Personally I'd say this is an oversight in Visual Studio 2008 SP1. Whenever you use refactoring to rename a property that is used in XAML, it wont change the name in the XAML, breaking any references you had to the property. I guess it's back to manually refactoring those.

Tab navigation on a popup doens't work by default
Whenever you use a popup control to display some controls, you can't use tab navigation by default. You'll need to add a content control to host this functionality. Jeff Handly explains it on his blog.

Allways make sure IsolatedStorageSettings.Save() is called at some point
Altough Save is called automatically called whenever a Silverlight application ends, this could actually fail, without you noticing. If, for some reason, saving settings throws an exception, you will not be able to tell this, because the application already ended. But if you call Save, it will throw the exception at that point and you can resolve any issues.

Make sure your webservices are thread safe
This may not seem like a Silverlight tip, but I put it here, because in most cases the Silverlight programmer is confronted with the initial exceptions. Inside the webservice, if you use a non thread safe object, make sure you do not share instances throughout your code. Create new once as needed and destruct them as soon as you're done. Read more about it here.
You may want to check back here, as chances are I'll post new information here from time to time.

No comments:

Post a Comment