Porting Silverlight 1.1 to Silverlight 2.0


.

Here are a few changes that you need to do to port Silverlight 1.1 project to Silverlight 2.0.

After 3 days of hustle with my previous code and thousands of errors in that, finally I was able to port my Silverlight 1.1 project to Silverlight 2.0. But still it doesn’t use all the cool features provided by Silverlight 2.0 like Grids and all. But I hope to refractor my code soon for better performance by using Silverlight’s native controls rather than my own. While porting the code, few of the things I had to change again and again as I had used them heavily. So here I’ve mentioned a few of them and hope it’ll be useful for you guys.

This is by no way an exhaustive list, but it may help you to quickly change some of the commonly used code and get it running on Silverlight 2.0 and Visual Studio 2008.

  1. As I mentioned in my previous article, you need to edit your previous project file.
  2. Change HtmlTimer To System.Windows.Threading.DispatcherTimer
  3. HtmlPage.Navigate(link) To HtmlPage.Window.Navigate(new Uri(link))
  4. You can directly use Static function HtmlPage.Document.GetElementsByTagName to get DOM elements.
  5. You can directly use HtmlPage.Document.CreateElement("Div") to create DOM elements
  6. XamlReader requires xmlns unlike Silverlight 1.1. XamlReader.Load(“<Canvas/>”); To XamlReader.Load("<Canvas xmlns="http://schemas.microsoft.com/client/2007"/>");
  7. FontWeights enumeration has been changed to a static class FontWeight.
  8. Change System.Windows.Media.Color.FromRgb(118, 118, 118) To System.Windows.Media.Color.FromARgb(255,118, 118, 118)
  9. this.MouseLeave += delegate(object sender, EventArgs e) To this.MouseLeave += delegate(object sender, MouseEventArgs e)
  10. this.MouseLeftButtonUp += delegate(object sender, MouseEventArgs e) To this.MouseLeftButtonUp += delegate(object sender, MouseButtonEventArgs e)
  11. In MouseEventHandlers, e.ctrl To ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
  12. ActualWidth of Silverlight Control

    System.Windows.Interop.BrowserHost.ActualWidth; To

    System.Windows.Interop.SilverlightHost silverlightHost = new System.Windows.Interop.SilverlightHost();

    width = silverlightHost.Content.ActualWidth

  13. In Silverlight 2.0, Managed Downloader has been removed.So you’ll have to use WebClient.

For a complete list, visit http://msdn2.microsoft.com/en-us/library/cc189007(vs.95).aspx




Comments

  1. scott
    March 11th, 2008 | 2:07 am

    great info. thanx dude

Leave a reply