TextBlock 在 WPF 中显示 HTML
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1070996/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TextBlock to Display HTML in WPF
提问by azamsharp
Is there anyway to display HTML from a string variable to the TextBlock in WPF?
无论如何要在WPF中将HTML从字符串变量显示到TextBlock?
回答by Sergey Aldoukhov
Can't do it in TextBlock, you need a WebBrowser control(or Frame, but it is obsolete). Feed descriptions, btw, can contain JavaScript - would be pretty hard for TextBlock to handle ;)
在 TextBlock 中无法做到,您需要一个WebBrowser 控件(或 Frame,但它已过时)。提要描述,顺便说一句,可以包含 JavaScript - TextBlock 很难处理;)
回答by Muis
Maybe you can use this WPF Html supported TextBlock
也许你可以使用这个WPF Html 支持的 TextBlock
回答by Rakshith
string html = "<div>hi</div>
<div> </div>
<p>this is the new line <br /><br />second line</p>
<p>third line</p>
";
字符串 html = " <div>hi</div>
<div> </div>
<p>this is the new line <br /><br />second line</p>
<p>third line</p>
";
TextBlock.Text = Windows.Data.Html.HtmlUtilities.ConvertToText(html);
TextBlock.Text = Windows.Data.Html.HtmlUtilities.ConvertToText(html);