Reputation: 1546
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
Upvotes: 2
Views: 5824
Reputation: 6365
There´s another approach, that is building the parts (blocks) of a XAML RichTextBlock
from an Html text. It involves more work than a WebView and it´s hard to support all tags, but if you just need a limited subset of html tags and you want more formatting control it´s very handy. Take a look at this repo
You basically bind your description property:
<RichTextBlock html:Properties.Html="{Binding description}"/>
Here´s an example:
Upvotes: 0
Reputation: 301147
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
Upvotes: 4