views:

84

answers:

2

I've seen a lot of stuff online that shows proof of concept tutorials of how Silverlight can be used to enhance web pages by handing tasks off to it to make use of threading, manipulate the DOM, achieve Comet-like functionality etc.

It all seems very interesting, however, has any one got any real world use cases to share as I can't seem to find many.

+3  A: 

Sure. I have used the HTML DOM interaction for several reasons.

First, when migration an existing ASP.NET application to Silverlight. In the architecture we worked with, the application was very heavily AJAX-based with plenty of callbacks. Instead of reinventing the wheel for Silverlight, we were able to use the DOM interaction to provide a bridge so the Silverlight control could callback in a similar fashion. This meant using the ASP.NET security and viewstate information to fetch information from the server and pull into the Silverlight application. We were already returning data in a JSON format so it was straightforward to parse back into the Silverlight application.

Another example is interaction with third-party controls and services. For example, Google Analytics provides rich page tracking features. This project provides a prime example:

http://silverlightanalytics.codeplex.com/

Where the application can integrate and even though you are running in Silverlight, you are essentially tracking clicks, actions, and page views.

Another place I've used this is when Silverlight isn't used as an application, but instead more of a part or a control on the page. While Silverlight controls can communicate with each other using the local communication, this doesn't work with other non-Silverlight controls. By using the HTML-DOM bridge you can easily build JavaScript-based communicatin between the components. Maybe the Silverlight control, for example, is an interactive world map that allows you to browse to a region. When you select the region, it raises a JavaScript event that the other controls listen to and update based on that reason.

You can also use Silverlight as a control like a Captcha control where your form uses the DOM bridge to validate user input into the Silverlight application.

I've seen tag cloud applications where the Silverlight control uses the DOM interaction to walk the current page and then generate an animated cloud of tags based on this.

Hopefully those provide some real world examples.

Jeremy Likness
+1  A: 

One thing I've used the DOM-Bridge for is to raise events. The html pages that host my application subscribe to these events and react consequently.

For example, my application receives and displays sales data coming from a WCF webservice. When the data changes, an event is raised so that the rest of the page can display other things.

If you can't use ASP.Net, asking and receiving data from a webservice is much easier and less error-prone in Silverlight than in Javascript (and is also faster because you can use the optimized "binary-xml" encoder).

I think the DOM bridge is most useful when you distribute a silverlight app to be embedded in arbitrary websites where you can't make assumptions on the backend environment but need to provide ability to interact with the SL app.

Francesco De Vittori
Thanks for the info. All the tutorials on the net seem to focus on the basic "call JS from silverlight and vice-versa" with little real world examples.