A lap through Silverlight (a deeper look into what is coming in 1.0 and 1.1)
Last week I mentioned that Silverlight is designed to work for all languages, platforms, browsers, etc right? Right.
But you are a smart cookie. You know that deep down, the boys at Redmond really want you to develop with ASP.NET right? Right.
So how do they lure you? Simple…better tools. While you can call Silverlight objects from any language, if you want to use the sweet tools they are making, then you have to be in ASP.NET.
The next question is: what are these tools and when do they come out (guess that is really 2 questions)? Glad you asked.
Silverlight (which I call SL in this article from time to time) currently comes in 2 flavors: 1.0 Beta and the 1.1 Alpha…which should you go with? Lets break it down.
1.0 Beta
So what sweet Silverlight goodness comes with 1.0? Two controls…yup, that’s it…but the good news is that both of these controls are heavy hitters, so there is a lot to love.
Media Control
First we have the ASP.NET Media control. Now as you might have guessed, this is how you show Media through Silverlight. You can stream videos in glorious 720p with one of these little guys. I am not sure what Flash’s max resolution on video is, but the MS guys says that it isn’t 720p. Not sure how necessary that is. I mean if you are a movie studio that that is pretty sweet. However most companies don’t need a wall of video, but I guess its still better to have it than not to right?
Now what is also cool is that, if you want, you can skin the media control with Xaml. Microsoft has kindly packaged several skins (made by Blitz Labs), with the beta, but they are just a starting point. With a tool like Expression Blend, you really can make it look however you want.
Also the control supports things like Closed Captioning, and chapter selection (just like a DVD movie). All in all, if you need to stream some media, you can really do it with style with this control. As I mentioned before, getting adoption of SL to a sufficient number will depend greatly on how well the YouTubes of the net utilize the tech, so it makes sense that the media control is full featured.
Xaml Control
So video is cool and all that, but can’t this thing do something besides media? Yup.
Enter the xaml control.
Basically the point of this control is to link to a SL object (which is basically a bunch of Xaml). For all intents and purposes, this is like adding a little flash movie in the middle of your page. Can’t I do this in Ruby? Basically with Javascript you can. However with ASP.NET you can debug it. Put some breakpoints, step through it, the whole nine-yards.
That basically does it for 1.0. To sum it up, if you just want something pretty in your ASP.NET page, then 1.0 will fit the bill. However, if you want to do some heavy lifting (i.e. get some data, manipulate it, save it back to the database), then you are gonna need 1.1.
1.1 Alpha
Give me data!
In 1.1 you can begin to call Web Services to bring back some data to play with. So now you can take that pretty doodad you made in 1.0 and get it to actually do something. A cool aspect of this is that 1.1 supports JSON Web Services. This basically means that you can bring back your data and use JSON syntax to get it out. To do this, all you need to do is put [ScriptService] as an attribute over your method in your web service and poof…the data JSON ready.
That’s the good news….the bad news is, in 1.1 all the web services that your site is gonna call must be part of the same site. This could be a deal breaker for a lot of people because it basically means that in 1.1 you will not be able to call 3rd party services. Bummer.
Downloader
The Downloader is a 1.1 SL control that basically tells your site to go start downloading things in the background. When it is finished there is a Completed method that tells the page that it is finished. This is really useful for say a portfolio site that has a lot of images on there. When the site initially loads you tell the Downloader to start getting all the images. This way while the user is looking at the first few, the rest of the images are downloaded which will dramatically speed up the loading process and the user will have a more seemless experience.
Here is a video from MS that goes into more detail about the Downloader.
BrowserHost
This is a new object that allows you to know the properties of the browser (such as its width and height) on the server side. This is a big one because there are a lot of times you are building something dynamic on the server side but you don’t know how to position things because you have no idea how big the browser is.
State Bookmarking
One of the biggest complaints of Flash is the fact that you cannot store your state so bookmarking is useless. With SL that is no longer an issue. Imagine watching a movie on the web and your boss comes in…
In Flash you would have to start over, but in Silverlight you can actually store the exact place you are in the movie so when you come back you pick up where you left off. Same goes for navigation with a SL control. Here is how it is done.
HTMLPage is a new object that represents the actual page. Using the CurrentBookmark property you can actually change and maintain where the user is taken when they save a bookmark. For example…say you have 100 images in a slideshow. With each image change you can update CurrentBookmark so that the user can save a bookmark to come to the exact image they are viewing.
The Framework
The biggest aspect of 1.1 is the fact that your silverlight objects can use a the .NET Framework to get some real work done. Its not the whole enchilada, but it is the more common stuff (collections, reflection, regular expressions, string handling, data access, and LINQ) is available.
With this version the simplified Framework will actually be installed on the client’s computers. The MS devs say this gives a performance boost of several hundred percent…that is a claim I am gonna have to see to believe…but it is probably pretty safe to say that the framework will be speedy.
Client…meet Server
SL can interact with the browser DOM and can wireup client events. Also, you can call server objects from the client side. Just do the following:
- Mark both the class and the method itself with the attribute [Scriptable]
- In the “Page_Load” method on the server add the following line: WebApplication.Current.RegisterScriptableObject[”methodname”].
- In the JS do something like this:
var x = document.getElementByID(”id of the asp:xaml control”);
x can now call the scriptable methods
Sweet eh?
Isolated Storage
Need to save something on the client without having to worry about security? 1.1 introduces Isolated Storage for the web (IS is not a new concept, but it hasn’t really been used much on the web side). Basically this means you can store up to 1 MB (this may grow in later versions) of just about anything on the client. You don’t really control where the data goes on the client (to do that would be a security risk). Basically you say “save this” and SL stores it in a place that is locked down from a security standpoint (so you can’t do anything nefarious). All of this can be done without having to notify the user that anything has happened at all.
New File Dialog
Ever get tired of having to upload files one at a time? SL will have a new file dialog (that works on multiple platforms) that will allow you to select multiple files at the same time. Awesome.
BackgroundWorker
For the more advanced coders out there, SL introduces the BackgroundWorker object. This little guy allows you to do background tasks on a separate thread allowing parallel processing.
Whew…so there you have it…a more detailed look into Silverlight 1.0 and 1.1. There is a lot to it, and the web is practically bursting with great sites that explain all of this in detail. I plan to do another round of great links soon that will focus on the different objects and controls.

