The download for Silverlight 2 Beta 1 is now available (follow the link and scroll to the bottom of this page).
Silverlight 2 Beta 1 adds tons of functionality over the Silverlight 1.1 Alpha, and as expected will break a lot of the Alpha 1.1 samples that are out in the wild. I was lucky enough to participate in the early Beta builds for Silverlight 2 and have posted updated versions of several of my Silverlight 1.1 Alpha games and demos. Just follow the links in the details to the right of this page. To hopefully help some folks out, I would like to share some of what I learned while converting my Alpha 1.1 projects to Beta 1. Having written a lot of Alpha 1.1 code, I was quite daunted by the sheer number of changes.
To start, if you take a look at the Silverlight 2 Help File, there is a section called “Breaking Changes Silverlight 2” which is a good starter which covers a lot of the common issues.
A lot of credit for these fixes goes to the Silverlight Insiders group I was involved with, and the beta support forums.
New DispatcherTimer instead of Empty Storyboard
Prior to Silverlight 2.0 Beta, there was no proper timer class available – instead, we needed to fake a timer using a Storyboard. But Beta 1 now includes a DispatcherTimer class, which makes creating custom timers cleaner (for things like a Game Loop):
_timer = new DispatcherTimer();
_timer.Interval = new TimeSpan(20);
_timer.Tick += new EventHandler(_timer_Completed);
Why aren’t my Sound Files Playing in Silverlight 2.0?
Thanks to Adam Kinney and Bill Reiss for the answer to this one. When migrating my Silverlight 1.1 Alpha code, it seemed none of my .wma sound files would play. Instead, I would get a MediaError – AG_E_UNKNOWN_ERROR when my application loaded. Checking the HTTP Request statuses shows that the request is looking for the WMA files in a location relative to ClientBin. This is due to how the new Silverlight Project Template packages things up for deployment.
So to correct this, you have two choices: (1) place your sound files relative to ClientBin or (2) Set your sound files’ Build Action to Content, and then refer to them with a root reference “/folder/file.wma” such as below:
MediaElement newSound = new MediaElement();
newSound.Source = new Uri("/sounds/explosion1.wma", UriKind.Relative);
newSound.AutoPlay = false;
Why am I Getting an HTTP 404 Error on my Silverlight XAP file?
Make sure you add the appropriate MIME data types to your web server. Additionally you need to add xaml and dll mime types (if you did not for Alpha 1.1 as of yet)
What am I getting “An item with the same key has already been added” – Error in xaml if more than 1 element has the same xmlns: attribute”?
Previous builds of Blend placed addition xmlns attributes on named UI elements. You need to search for any xmlns attributes in your XAML and delete them.
Why I am I getting “User Control does not support Canvas as content”?
Be sure that the base class you are inheriting from is inherited from UserControl and not just “Control” or another class.
What happened to the BrowserHost class?
BrowserHost, which used to exist in System.Windows.Interop, is now missing. Instead, you can use:
System.Windows.Application.Current.Host.Content.Resized += new EventHandler(Content_Resized);
What happened to HtmlPage.Navigate and HtmlPage.DocumentUri?
System.Windows.Browser.HtmlPage.Navigate is now on the HtmlWindow class, accessible via:
… and also the current browser Document’s Uri can be found at:
What happened to MouseEventArgs and KeyboardEventArgs?
MouseEventArgs is now MouseButtonEventArgs
MouseEventHandler is now MouseButtonEventHandler
KeyboardEventArgs is now KeyEventArgs. Also, there is now an enumeration, System.Windows.Input.Key, which you can use instead of integer values for key codes.
KeyboardEventHandler is now KeyEventHandler
What happened to my MediaEnded Event Handler?
Events such as MediaEnded no longer use EventHandler and EventArgs. Instead they now use RoutedEventHandler and RoutedEventArgs. Example:
theSound.MediaEnded += new RoutedEventHandler(theSound_MediaEnded);
void theSound_MediaEnded(object sender, RoutedEventArgs e)
Why are some Generic Collections missing?
Some Generic and non-Generic Collections removed to save some space: http://blogs.msdn.com/bclteam/archive/2007/06/26/non-generic-collections-to-be-removed-from-silverlight-inbar-gazit.aspx
What happened to Rect.Intersect and the other Rect class utility methods?
Some Rect methods were moved to save space. However, you can use the following method in place of Rect.Intersect: (Also note that there is a new HitTest method which can be coerced into doing collision detection between two paths).
if (rect1 == Rect.Empty)
// No collision!
Why can’t I install Silverlight Beta 1?
When installing, I get the following error:
An Error Has Occurred:
Silverlight Tools cannot be installed because one or more of the following conditions is true:
1. Visual Studio 2008 RTM is not installed.
2. The Web Authoring feature of Visual Studio is not installed.
3. A previous version of the Silverlight Runtime is installed.
4. A previous version of the Silverlight SDK is installed.
5. The Visual Studio Update KBXXXXXX is installed.
6. A previous version of Silverlight Tools is installed.
To continue, please install or uninstall the …
This is usually due to the KBXXXXXX update. To find and remove this update, go to Add/Remove Programs and check the “Show Updates” checkbox at the top of the dialog. Then scroll down to “Microsoft Visual Studio 2008 Professional Edition – ENU” and you should see the KB install there.