How to display simple HTML in a Silverlight textblock?

五迷三道 提交于 2019-12-01 17:31:08
Noldorin

There's no native support in Silverlight 2.0. However, someone has gone and created a HtmlTextBlock control which should be suitable for your purposes. Check out the author's block post on the subject. There's also a demo page here.

If you want to do it just in XAML:

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

the &#160 is an antity for space. The result is:

Text: italic and bold

web marketing melbourne

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

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

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

I also had a problem where an exception was being thrown when the DOM parsing routine failed, and I fixed it by changing:

Xaml = null;

with

this.SelectAll();            
this.Selection.Text = ""; 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!