简体   繁体   中英

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

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

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

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:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM