Display Html in Silverlight

With Silverlight doing the rounds these days, folks at my workplace decided to build an application (a real-world app which hopefully our customers will use) using Silverlight. I, being always interested in technology, got to talk to them about it and help out wherever I can. At this point in time, all I can say is that we are trying to replace a Windows Forms client which runs on the user computer and calls upon web services on the server (which can be anywhere) for data upload and download. The obvious drawback of the current situation is that it requires .net Framework 2.0 installed on the computer running the client (and in our target market that is still a rarity).

So, Silverlight it is. We set about trying to make a 100% Silverlight app with no Html part whatsoever. Soon enough we ran into a problem: some of the data that we receive from the server side is Html, and we need to display it as is. So… how do you display Html in Silverlight? The answer is that you don’t. How we arrived at it was multi-step:

  • We tried to look for an XAML to HTML Parser. We found some but could never find one that was good enough to handle even the basic HTML that we were producing (one particular problem was handling on <img> tags). Anyway, the produced Html was not Silverlight compliant anyway.
  • We started writing our own, but it looked like a lot of effort, and we believed that such an advanced technology should be easier than that.
  • Finally, due to the fact that there seemed to be no other option, and also by some gentle prodding by experts towards this direction, we decided that we should have a mix Silverlight + Html solution.

So now, we are using Silverlight to act as a controller which communicates with the webservices, and controls the interaction with Html. So it displays the Html by injecting it in the page elements (a few strategically placed DIVs). It wires up any Html events to handlers within Silverlight (this is the killer part). Come to think about it, it’s almost like Asp.net except that it is running entirely in the client browser. We did face some trouble in trying to dynamically insert new Html elements into the page, but we didn’t explore that avenue as we don’t need them. We simply inject Html into already existing DIVs on the page.

Well, this will allow us to come up with a Prototype and then we can really start polishing it.

Important Update: We have the ability to have Html Overlays in SilveLight. Search for SilverLight Html Overlay in Google. 

If you found this content helpful, then please help by linking to me. You can also help me by sharing the content using any of these nifty buttons above. Thank you.



You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

3 Responses to “Display Html in Silverlight”

  1. Thanks Monkey :)

    Yes, this is promising. Although, it would still be a welcome addition if there was a full-fledged Html Display control in SilverLight.

    Reply
  2. Yes, overlay works very well indeed. One thing to remeber is process brower resize if you want the DIV to be positioned properly.

    why search in google? msdn should be a great place for any programmers. and as a matter fact Bing should be good for everyone. that’s the most stupid word, don’t use that.

    Reply




Leave a Reply