I love Silverlight and have written / talked about it a lot. I can’t help but notice that a lot of people are new to Silverlight or may have played with it a few times. Well this post is for you. It is a list of 15 things that I’ve discovered since I started developing for Silverlight. If you are a full-time Silverlight developer than I would hope you know most of these. I promise not to scare off anyone with talks of MVVM, Prism or MEF.
1) The line highlighted below represents the MIME type and it is not the runtime version of Silverlight. Many developers are at first confused about this because they think it is referring to the Silverlight version (example: Silverlight 4).
HTML/ASPX markup of a Silverlight Hosted Application
2) You can’t use .GIF images with Silverlight. Use .PNG files if you need images in a Silverlight application. If you must use .gif’s then you should consider using the .NET Image Tools Library for Silverlight. Many people are also building web services that will convert the .gif files to .PNG. I would recommend converting the images to .PNG with a tool like Paint.NET.
3) If a user does not have the Silverlight 4 plug-in installed, users are prompted to download it by the following line of code (found inside the .ASPX or HTML file):
If you change the link to :
<a href="http://go.microsoft.com/fwlink/?LinkID=149156" style="text-decoration: none;">
<img src="http://go.microsoft.com/fwlink/?LinkID=161376" alt="Get Microsoft Silverlight" style="border-style: none"/>
Then it will always download the latest version of the Silverlight runtime. New versions are backwards compatible with old versions of the runtime.
4) All data access in Silverlight is asynchronous. The example below will not work:
MyOldWebService srv = new MyOldWebService();
string strReturn = srv.GetSomeValue();
txtValue.Text = strReturn;
This is how we would call a WCF service in Silverlight (for example after the InitializeComponent Method):
Service1Client client = new Service1Client();
client.DoWorkCompleted += new EventHandler<DoWorkCompletedEventArgs>(client_DoWorkCompleted);
void client_DoWorkCompleted(object sender, DoWorkCompletedEventArgs e)
5) Use templates / themes whenever necessary. Microsoft has provided 4 themes that will give your application a custom look. You can also use the built-in Navigation template included in VS2010 or the ones included in Blend 4 (which includes MVVM template). In other words, don’t start a project completely from scratch unless you need too.
6) Spend the time to learn Blend 4. Sure you can write all of your XAML (markup) from hand but why? Blend 4 was created to assist with creating applications for Silverlight, WPF and Windows Phone 7. I cannot imagine creating Storyboards and animations by hand. It has a learning curve but it is worth it in the end.
7) Make use of the Silverlight Toolkit available on CodePlex.
The Silverlight Toolkit is a collection of Silverlight controls, components and utilities made available outside the normal Silverlight release cycle. A product of the Microsoft Silverlight product team, the Silverlight Toolkit adds new functionality quickly for designers and developers, and provides the community an efficient way to help shape product development by contributing ideas and bug reports. It includes full open source code, unit tests, samples and documentation for over 26 new controls covering charting, styling, layout, and user input. – Taken from the codeplex site.
8) Be aware that your Silverlight code can be viewed by anyone using tools like Silverlight Spy/.NET Reflector. If your application is on the internet and not a internal application then you better obfuscate it. Its better to have some security than none. This also works the other way around and you can see how someone built a Silverlight application.
9) The .XAP file that your Silverlight project creates is simply a .zip file with a different extension. You can use an external program like 7zip to squeeze a smaller file size than the one included with VS2010. It also pays to open up a .XAP file and examine whets included with your project.
10) If a file is not necessary for every user then do not include it in the .XAP file. I’ve heard every argument against this saying,” bandwidth is cheap.” However, this method really gets expensive when its more than 50-100 images or other binaries. I only include the files absolutely necessary for every user of my application.
11) You can host a Silverlight application in other servers. You do not have to use IIS. Simply setup the MIME type on your WebServer and the Silverlight application will work on the client as long as the Silverlight run-time is installed.
12) The community rocks for Silverlight. There is a lot of ways to learn more about it. I’d start with the official Silverlight site, then check out the official forums. I’d also visit Silverlight Cream and Alvin’s Ashcraft’s Morning Dew daily. To finish up, I’d watch every episode of John Papa’s Silverlight TV.
13) Once you learn XAML (the markup for Silverlight) you can use those skills to produce applications for the following platforms: Silverlight (duh), WPF, Windows Phone 7, Lightswitch and Surface.
14) Silverlight works with all the major browsers (Google Chrome 6, IE, Firefox and Safari) and Operating Systems (such as Wiindows and Mac OS). It even includes support for Linux through the Moonlight project.
15) Users get the same experience no matter what browser they are running. Remember when one webpage worked fine in Firefox but not in IE6. Since Silverlight is a plug-in everyone gets the same experience.
“SAME EXPERIENCE EVERYWHERE”
Thank you for reading my blog post, as always feel free to subscribe to my feed or add me to twitter.
Subscribe to my feed