Can I render HTML in Silverlight?

1k views Asked by At

Is there any way to display formatted text in Silverlight?

I have a database of articles with HTML formatting (p,b,i,h1,h2 tags). I need to figure out a way to display them in a Silverlight application while retaining the formatting from the database.

2

There are 2 answers

1
casperOne On

There is an HtmlTextBlock control written by David Anson (from MS) which has support for the following HTML elements:

  • A
  • B
  • BR
  • EM
  • I
  • P
  • STRONG
  • U

Fortunately, the source is distributed, and you'd have to provide support for H* tags.

However, if you are using Silverlight 4, then you can use the WebBrowser class and just load your HTML into that. Just note (as santiagoIT does in the comments) that the WebBrowser control will only work if you are running out-of-browser.

0
Gonçalo Chaves On

I think that you don't have a standard oob control to do that. But I know some guys that develop theirs own control, like this one: http://blogs.msdn.com/b/delay/archive/2007/09/10/bringing-a-bit-of-html-to-silverlight-htmltextblock-makes-rich-text-display-easy.aspx It's simple but can solve your question. ;)