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, then I would hope you know most of these. I promise not to scare off anyone with talks of MVVM, Prism or MEF.
- 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
- You can't use .GIF images with Silverlight. Use .PNG files if you need images in a Silverlight application. If you must use .gifs, 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.
- 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:
alt="Get Microsoft Silverlight" style="border-style: none"/>
Then it will always download the latest version of the Silverlight runtime. New versions are backward compatible with old versions of the runtime.
- 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
Service1Client client = new Service1Client();
client.DoWorkCompleted += new EventHandler<DoWorkCompletedEventArgs>
void client_DoWorkCompleted(object sender, DoWorkCompletedEventArgs e)
- 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.
- 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.
- 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.
- 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 an internal application, then you better obfuscate it. It's better to have some security than none. This also works the other way around and you can see how someone built a Silverlight application.
- 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 what's included with your project.
- 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 it's more than 50-100 images or other binaries. I only include the files absolutely necessary for every user of my application.
- 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.
- The community rocks for Silverlight. There are 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.
- 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.
- Silverlight works with all the major browsers (Google Chrome 6, Internet Explorer, Firefox and Safari) and Operating Systems (such as Windows and Mac OS). It even includes support for Linux through the Moonlight project.
- Users get the same experience no matter what browser they are running. Remember when one webpage worked fine in Firefox, but not in Internet Explorer 6. 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