Bringing a bit of HTML to Silverlight [HtmlTextBlock makes rich text display easy!]

This blog has moved to a new location and comments have been disabled.

All old posts, new posts, and comments can be found on The blog of

See you there!


Comments (42)
  1. WynApse says:

    Silverlight Cream for September 11, 2007

  2. Need to display rich text in Silverlight? Go here to check out the demo here . click here to download

  3. This is a great control. We could have used the ability to display HTML text in the Carbon Calculator,

  4. Here is the latest in my link-listing series . Also check out my ASP.NET Tips, Tricks and Tutorials page

  5. Here is the latest in my link-listing series . Also check out my ASP.NET Tips, Tricks and Tutorials page

  6. Here is the latest in my link-listing series . Also check out my ASP.NET Tips, Tricks and Tutorials page

  7. ASP.NET says:

    Here is the latest in my link-listing series . Also check out my ASP.NET Tips, Tricks and Tutorials page

  8. Programming says:

    Here is the latest in my link-listing series . Also check out my ASP.NET Tips, Tricks and Tutorials page

  9. Delay's Blog says:

    I blogged about my HtmlTextBlock implementation for Silverlight a few days ago. In that post I described

  10. WynApse says:

    Silverlight Cream for September 25, 2007

  11. says:

    Expression Blend 2 September Preview

  12. ASPInsiders says:

    Here is the latest in my link-listing series . Also check out my ASP.NET Tips, Tricks and Tutorials page

  13. Delay's Blog says:

    A few months ago when Silverlight 1.1 Alpha was all the rage, I wrote a sample control that made a best-effort

  14. Si vous avez un peu joué avec la version Bêta 1 de Silverlight 2 vous avez certainement remarqué

  15. Delay's Blog says:

    A customer recently asked about an update to my HtmlTextBlock sample for the newly released Silverlight

  16. This is a great control. We could have used the ability to display HTML text in the Carbon Calculator, and I've run into the limitation in other projects. If you want to display HTML rich text in your Silverlight application, and don't feel like

  17. Delay's Blog says:

    A couple of readers have asked about an update to my long-running HtmlTextBlock sample for Silverlight

  18. Delay's Blog says:

    I updated my HtmlTextBlock sample for RTW last night and got an email from kind reader Ed Silverton this

  19. tevya says:

    I got down the source and was trying to see if I could add HyperLink objects instead of Run objects to the text block.  MSDN documents the HyperLink class but it does not seem to actually exist (in VS 2K8, .NET 3.5).  What’s up with that?  Was HyperLink withdrawn or just silently never implemented?

  20. David Anson says:


    System.Windows.Documents.Hyperlink is available in the PresentationFramework assembly of WPF. It’s not present in Silverlight because Silverlight doesn’t yet support the Documents namespace, etc.. But Silverlight has HyperlinkButton which can be useful for some related scenarios – though not what you’re trying to do here, if memory serves.

    Hope this helps!

  21. John Waters says:

    Awesome. Do you have a version that works on the WinPhone 7? HtmlPage does not appear to exist there…

  22. David Anson says:

    No, but it's an interesting idea! 🙂 That said, Windows Phone applications have access to a WebBrowser control in the platform which I understand is fairly well suited to this scenario. Have you tried using that yet?

  23. Chris Rae says:

    I was after the same thing as John – the WP7 WebBrowser control didn't work for what I was after because it doesn't support transparency. 🙁

  24. David Anson says:

    Chris Rae,

    Okay, I've added a TODO to my blogging list for creating an example of using HtmlTextBlock on Windows Phone 7. 🙂 I'm optimistic it'll be an easy conversion (modulo the missing HtmlPage class which I think will only affect the UseDomAsParser feature) – you might want to give it a go in the meantime and see how it works out!

  25. Saravana Kumar says:

    It works great on static text cases where I put something in XAML Text="Hello <br/> <b>there</b>" directly. But it fails on data binding scenarios. It simply displays the text like this Hello <lt>b</gt>there<lt>b</gt>

  26. David Anson says:

    Saravana Kumar,

    Binding shouldn't be an issue – but invalid HTML could be. The sample you give that fails looks like maybe the '<' and '>' characters got messed up along the way (or maybe that's the MSDN blog engine messing up your comment…). At the end of the day, a control doesn't usually know/care how it gets its property values – the same value provided directly or via Binding will usually have the same effect. So my first thought here is that the text you were Binding wasn't quite exactly the same and that's what got in the way.

  27. Saravana Kumar says:

    Hi Delay, the formatting you see in the comments are due to msdn blog engine parsing html characters. You are right, I tried with a local project and everything seem to be working correctly with data binding and also using a converter. The mistake I made was when you specify the html text in XAML directly Text="html content", then you need to escape all the html characters, whereas when you data bind the property  it can simply return HTML content without escaping any html characters.

  28. Shishira says:

    Hi David,

    I am using this control and I am really happy that it reduced my work. But I am not able to get the scroll bars when there is lots of text. Could you please let me know how to fix this issue .

    I tried  ScrollViewer.VerticalScrollBarVisibility="Visible" already

    Thanks in advance

  29. David Anson says:


    I'm guessing you'd see the same behavior with TextBlock (i.e., it's not related to HtmlTextBlock). What should work is wrapping your content (ex: the HtmlTextBlock) in a ScrollViewer control – that will automatically add scroll bars when necessary.

    Hope this helps!

  30. Pitta says:

    I too just realized that this isn't working properly in WP7. This would be fantastic if it did!

  31. David Anson says:


    Windows Phone 7 offers the web browser control for these kinds of scenarios which will natively offer much better HTML support than the handful of things I did for HtmlTextBlock:…/ff431811(VS.92).aspx

    Do you think you might be able to use that control instead? If not, I'd love to hear why not and how you think HtmlTextBlock could do a better job for you.


  32. el-sio says:

    Hi there and thank you for this nice work !

    I would alse really wish this would work in WP7, because

    => loading IE for simple text formatting (just strong br and an occasionnal a) is really too heavy.

    => you can't tell the webbrowser content how high or wide it should be relying on the "auto" keyword, which I suppose you could do with htmltextblock. so you will have to handle the double scrolling of your IE and your page, and it's really annoying.



  33. David Anson says:


    Thanks for the kind words! I've just added a note to my TODO list to look into creating a Windows Phone version of the HtmlTextBlock sample – though I'm not sure how quickly I'll get around to doing so. I agree with your motivation, though – that's part of why I created HtmlTextBlock in the first place. 🙂

  34. Tom says:

    David Anson : Any update about HtmlTextBlock Windows phone 7 version bro ?

  35. el-sio says:

    Thank you for the answer David, and I wish you luck for the implementation.

    I'll check this page every day for any update about the release but no pressure 😉

    And BTW, I've just added a new good reason to the list :

    – You can't justify text in a WP7 textblock, the method is only relevant for controls such as richtextblocks, which are of course not available for WP7… (see…/



  36. David Anson says:


    Sorry to keep you waiting! 🙁 This item's on my TODO list like I said, but so are a bunch of other things. 🙂 Let me ping Morten and see if he might get to this sooner…


  37. Morten says:

    I haven't had time to look into this, and probably won't before Mango releases. Mango includes support for Silverlight 4, which I can only assume includes RichTextBox support, so the existing sample should soon work on WP7.

  38. Gautam says:

    Unable to convert below html text can anybody help please

    "<P style='MARGIN: 0in 0in 0pt; WIDTH: 770px; HEIGHT: 28px' class=MsoNormal><SPAN style='FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; mso-fareast-font-family: Arial; mso-bidi-font-family: 'Times New Roman''>Decrease due to early renewal of Wells Fargo – includes 12 months of free rent on 10 year term.</SPAN><o:p></o:p></P>"

  39. David Anson says:


    There's some sketchy quoting going on with the span element's style property, but the real problem here is the "<o:p></o:p>" – removing that lets it render fine. I think the problem is the missing XML namespace definition for the "o" prefix.

  40. Thanks you very much for this code. Needed to get something out quickly for an old Silverlight 3 project and this worked perfectly.

  41. Nevron Software says:

    Great free control, too bad it does not support tables like the commercial ones (DevExpress, Nevron etc.)

Comments are closed.

Skip to main content