Partager via


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

  • Anonymous
    September 11, 2007
    The comment has been removed

  • Anonymous
    September 11, 2007
    Need to display rich text in Silverlight? Go here to check out the demo here . click here to download

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

  • Anonymous
    September 16, 2007
    The comment has been removed

  • Anonymous
    September 16, 2007
    The comment has been removed

  • Anonymous
    September 16, 2007
    The comment has been removed

  • Anonymous
    September 16, 2007
    The comment has been removed

  • Anonymous
    September 18, 2007
    The comment has been removed

  • Anonymous
    September 19, 2007
    Thursday Linkorama

  • Anonymous
    September 24, 2007
    I blogged about my HtmlTextBlock implementation for Silverlight a few days ago. In that post I described

  • Anonymous
    September 25, 2007
    The comment has been removed

  • Anonymous
    September 26, 2007
    Expression Blend 2 September Preview

  • Anonymous
    October 03, 2007
    The comment has been removed

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

  • Anonymous
    April 21, 2008
    Si vous avez un peu joué avec la version Bêta 1 de Silverlight 2 vous avez certainement remarqué

  • Anonymous
    June 11, 2008
    A customer recently asked about an update to my HtmlTextBlock sample for the newly released Silverlight

  • Anonymous
    June 28, 2008
    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

  • Anonymous
    November 11, 2008
    A couple of readers have asked about an update to my long-running HtmlTextBlock sample for Silverlight

  • Anonymous
    November 12, 2008
    I updated my HtmlTextBlock sample for RTW last night and got an email from kind reader Ed Silverton this

  • Anonymous
    February 11, 2009
    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?

  • Anonymous
    February 11, 2009
    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!

  • Anonymous
    July 23, 2010
    Awesome. Do you have a version that works on the WinPhone 7? HtmlPage does not appear to exist there...

  • Anonymous
    July 23, 2010
    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?

  • Anonymous
    October 24, 2010
    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. :(

  • Anonymous
    October 25, 2010
    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!

  • Anonymous
    October 25, 2010
    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>

  • Anonymous
    October 26, 2010
    The comment has been removed

  • Anonymous
    October 27, 2010
    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.

  • Anonymous
    February 01, 2011
    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

  • Anonymous
    February 02, 2011
    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!

  • Anonymous
    February 11, 2011
    I too just realized that this isn't working properly in WP7. This would be fantastic if it did!

  • Anonymous
    February 11, 2011
    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!

  • Anonymous
    April 12, 2011
    The comment has been removed

  • Anonymous
    April 12, 2011
    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. :)

  • Anonymous
    April 16, 2011
    David Anson : Any update about HtmlTextBlock Windows phone 7 version bro ?

  • Anonymous
    May 02, 2011
    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 :

  • Anonymous
    May 02, 2011
    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: www.sharpgis.net/.../Displaying-HTML-in-Silverlight.aspx

  • Anonymous
    May 02, 2011
    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.

  • Anonymous
    August 06, 2012
    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>"

  • Anonymous
    August 08, 2012
    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.

  • Anonymous
    September 26, 2012
    Thanks you very much for this code. Needed to get something out quickly for an old Silverlight 3 project and this worked perfectly.

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