2

Is there a quick and dirty way to render HTML in a textblock in a fashion similar to Android's Html.fromHtml()? I am aware of how to manually parse it with something like the HtmlAgilityPack, but all I really want is for it to render like its source in the textblock.

If not naively then perhaps with a custom control of some sort and, no I don't want to render it as a web page.

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
Terrance
  • 11,764
  • 4
  • 54
  • 80
  • 1
    Is there something from TextBlock you need and can't get using Browser Control? I am sure you have thought about it but adding it anyway. Not as a web page but, you can include a browser control in your page and parse HTML string into it. browserCtrl.NavigateToString("HTML Text"); – Vivek Nirkhe Oct 01 '11 at 23:19
  • @Claus there is one now. Smashed together a quick and dirty solution tweeking HtmlAgility and HtmlTextblock. see here (http://blogs.msdn.com/b/delay/archive/2007/09/10/bringing-a-bit-of-html-to-silverlight-htmltextblock-makes-rich-text-display-easy.aspx) I'll upload to github tonight. – Terrance Oct 03 '11 at 15:30

1 Answers1

4

Ok sorry it took so long. I all but forgot how to use git correctly and hadn't had the time to upload till now. This HtmlTextBlock offers a similar level of functionality as to that of its silverlight counterpart which is pretty close to the android equivalent. Its still a bit buggy at times when dealing with more complex tags like the html dtd tag but does the job.... WP7 Html Text Block. The design is largely based on this guy's Bringing-a-bit-of-html-to-silverlight-htmltextblock-makes-rich-text-display-easy. and rewriting the web browser related classes using html agility. One day I'll post the details but, blah... Not right now. lol

Update

Example of usage:

<local:HtmlTextBlock x:Name="htmlTextBlock" Canvas.Left="2" Canvas.Top="2" TextWrapping="Wrap" UseDomAsParser="true" Text="&ltp&gtYour Html here &lt/p&gt" />

Note: Your html will have to be escaped such that &lt = < and &gt = >

For detailed usage see:

https://github.com/musicm122/WP7HtmlTextBlock-/blob/master/HtmlTextBlockTest/HtmlTextBlockTest/MainPage.xaml

Terrance
  • 11,764
  • 4
  • 54
  • 80
  • 2
    Glad you took the time, and did the the initial effort. – Claus Jørgensen Oct 23 '11 at 17:11
  • It was pretty fun. I enjoyed it. – Terrance Oct 23 '11 at 17:26
  • Hi @Terrance.. Can you provide any sample or example for Html.fromHtml() in WP7?? Please.. – Vijay Jan 21 '15 at 10:43
  • @Vijay It doesn't work 1:1 that way with the control. You could update the Text property with the html you want to use and get pretty close to what you want. I update the answer and the docs to make things a bit clearer. – Terrance Jan 21 '15 at 15:32
  • @Terrance.. Thanks.. It is working.. But, it will not support images ah?? [This](http://stackoverflow.com/questions/28065062/equivalent-to-html-fromhtml-in-windows-phone-7/28081210#28081210) is my question. Can i use this control for this requirement?? – Vijay Jan 22 '15 at 05:05