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 dlaa.me.

See you there!

SilverlightHtmlTextBlock.png

Comments (42)
  1. Anonymous says:

    Silverlight Cream for September 11, 2007

  2. Anonymous says:

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

  3. Anonymous says:

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

  4. Anonymous says:

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

  5. Anonymous says:

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

  6. Anonymous says:

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

  7. Anonymous says:

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

  8. Anonymous says:

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

  9. Anonymous says:

    Thursday Linkorama

  10. Anonymous says:

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

  11. Anonymous says:

    Silverlight Cream for September 25, 2007

  12. Anonymous says:

    Expression Blend 2 September Preview

  13. Anonymous says:

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

  14. Anonymous says:

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

  15. Anonymous says:

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

  16. Anonymous says:

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

  17. Anonymous says:

    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

  18. Anonymous says:

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

  19. Anonymous says:

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

  20. 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?

  21. David Anson says:

    tevya,

    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!

  22. Anonymous says:

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

  23. 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?

  24. Anonymous 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. 🙁

  25. 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!

  26. Anonymous 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>

  27. 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.

  28. Anonymous 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.

  29. Anonymous 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

  30. David Anson says:

    Shishira,

    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!

  31. Anonymous says:

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

  32. David Anson says:

    Pitta,

    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: msdn.microsoft.com/…/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.

    Thanks!

  33. Anonymous 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.

    Best,

    Charles.

  34. David Anson says:

    el-sio,

    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. 🙂

  35. Anonymous says:

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

  36. Anonymous 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 msdn.microsoft.com/…/system.windows.textalignment(v=VS.96).aspx)

    Best,

    Charles.

  37. David Anson says:

    Tom/el-sio,

    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…

    Context: http://www.sharpgis.net/…/Displaying-HTML-in-Silverlight.aspx

  38. Anonymous 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.

  39. Anonymous 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>"

  40. David Anson says:

    Gautam,

    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.

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

  42. Nevron Software says:

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

Comments are closed.