How to display plain HTML in a Silverlight text block?

I have a data source that has HTML tags (B, I, A) in it, and you need to display this in a Silverlight ListBox.

Searching around seems to be a problem, but most posts are old and related to Silverlight 1. It seems.

Currently, the best way to display plain HTML with Silverlight, if nothing else, is just the B, I, and A tags for bold, italic, and hyperlinks?

+7
html silverlight textblock
source share
3 answers

Silverlight 2.0 does not have native support. However, someone set off and created an HtmlTextBlock control that should be suitable for your purposes. Write down the author's block post on this. There is also a demo page here .

+3
source share

If you want to do this only in XAML:

 <TextBlock> Text:&#160;<Italic>italic</Italic>&#160;and&#160;<Bold>bold</Bold> </TextBlock> 

& # 160 is the prototype for space. Result:

Text: italics and bold

0
source share

This comment system is crazy. Last night I added 2 comments. After adding the second I still could see only the first. This morning, after clearing the browser cookies, I see only my second. Wierd.

Anyway, I had a problem with the control where I had the Html property and it added html every time the property changed. I fixed it by adding the following to the beginning of the ParseAndSetText() method:

 this.SelectAll(); this.Selection.Text = ""; 

I also had a problem when an exception was thrown, when the DOM parsing procedure was running, and I fixed it by changing:

 Xaml = null; 

from

 this.SelectAll(); this.Selection.Text = ""; 
-one
source share

All Articles