user1428798
user1428798

Reputation: 1546

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

Upvotes: 2

Views: 5824

Answers (3)

xleon
xleon

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:

enter image description here

Upvotes: 0

manojlds
manojlds

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

Sean
Sean

Reputation: 62472

Take a look at the WebView control. There's a NavigateToString method that may help.

Upvotes: 1

Related Questions