user1428798 user1428798 - 1 month ago 22
C# Question

Render Html in XAML + windows 8

I have a proprety in my model that contain HTML ex:

public class watch
{
public string description=<div>hello<br/> world</div>
}


I need in the view in xaml code to bind this description with a composant.
which composant should i use (RichTextblock or ...) to render this html??
if i use
<textblock text={binding="descrption"}/>
the html tags still visible, i need to return to ligne and do not show html tags

Any ideas please??

Best regards

Answer

The WebView control gives us a way to host HTML data within our app. But if we look at its Source property, we see that it takes the Uri of the web page to display. Our HTML data is just a string of HTML. It doesn't have a Uri that we can bind to the Source property. Luckily, there is a NavigateToString method that we can pass our string of HTML to.

So do:

ContentView.NavigateToString(w.description);

http://msdn.microsoft.com/en-us/library/windows/apps/br211380.aspx