简体   繁体   English

在XAML + Windows 8中渲染HTML

[英]Render Html in XAML + windows 8

I have a proprety in my model that contain HTML ex: 我的模型中有一个包含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. 我需要在xaml代码中的视图中将此描述与构成要素绑定。 which composant should i use (RichTextblock or ...) to render this html?? 我应该使用哪个编辑器(RichTextblock或...)来呈现此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 如果我使用<textblock text={binding="descrption"}/> html标记仍然可见,则需要返回ligne并且不显示html标记

Any ideas please?? 有什么想法吗?

Best regards 最好的祝福

The WebView control gives us a way to host HTML data within our app. WebView控件为我们提供了一种在应用程序中托管HTML数据的方法。 But if we look at its Source property, we see that it takes the Uri of the web page to display. 但是,如果我们查看其Source属性,就会发现它需要显示网页的Uri。 Our HTML data is just a string of HTML. 我们的HTML数据只是一串HTML。 It doesn't have a Uri that we can bind to the Source property. 它没有可绑定到Source属性的Uri。 Luckily, there is a NavigateToString method that we can pass our string of HTML to. 幸运的是,有一个NavigateToString方法,我们可以将我们的HTML字符串传递给该方法。

So do: 这样:

ContentView.NavigateToString(w.description);

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

Take a look at the WebView control. 看一下WebView控件。 There's a NavigateToString method that may help. 有一个NavigateToString方法可能会有所帮助。

There´s another approach, that is building the parts (blocks) of a XAML RichTextBlock from an Html text. 还有另一种方法,就是从HTML文本构建XAML RichTextBlock的部分(块)。 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. 它比WebView涉及更多的工作,并且很难支持所有标记,但是如果您只需要html标记的有限子集,并且想要更多的格式控制,则非常方便。 Take a look at this repo 看看这个回购

You basically bind your description property: 您基本上绑定了description属性:

<RichTextBlock html:Properties.Html="{Binding description}"/>

Here´s an example: 这是一个例子:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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