31 July 2008

How to dispaly HTML/rich text in Silverlight

Silverlight is intended for making applications way more that for making websites. If what you're making is more like a website (and what I'm working on definitely is), you're gonna want to put content, and if you're putting content, you're most probably putting text, and if you're putting a lot of text, you're gonna want to format it. And you've been formatting text in HTML since your early childhood, so your'e wondering how to insert this dear HTML of yours into a Silverlight application website.

You have three possibilities:

  1. Formatting text using the "Run" element.
  2. Using the HtmlTextBlock control written by Delay, which supports the tags: a, b, br, em, i, p, strong and u (but no CSS).
  3. HTML Overlay:
HTML overlay is explained here (and that's where the picture's from).

I'm trying HTML overlay today.


  1. Thanks for the post.
    I'm a fan of yours.
    It's that your posts are different from others. It has something that attracts me. Is it because you are a female (which I believe is rare in the computing world) and I'm a male? :) No, I don't think so.
    So I hope you keep the good posts going.

  2. Yeah, non the options to display HTML in silverlight is perfect right now.

    here's the short coming:
    1. Formatting HTML into a TextBlock - All the disadvantages of point (2) and than you have to build it. It's a lot of time and resources since HTML & CSS are a pretty complex rendering format.
    2. Using the HtmlTextBlock - David Anson rules :)
    but, as you mentioned HtmlTextBlock doesn't support the full HTML & CSS spec. Here's an interesting question for you, say you've got a browser rendering bug in IE, do you recreate it? if you don't, than your HTML rendering engine isn't feature complete. if you do, than your HTML rendering engine has to rebuild all the little quirks of all major browsers out there.
    3. Html overlay. The problem with that is that it's a hack. and like all hacks - you're closing doors you didn't even think you need. A good example of an option this hack closes is using a window modal in your silverlight app. Let's say you've got "Control A" and it's partially obscure by "Overlay A" - that would work. But now let's say you've got "Silverlight DialogBox A" obscuring "Overlay A" - there's no way to render that.

    So yeah, HTML in silvelirght isn't easy. It's all about comprising and balancing how much time you'd like to invest in this and what kind of results are you expecting.

  3. Hi, chilly!

    Wanna try some HTML?

    I recently found that link, hope it might be helpful