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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 20:39:42  来源:igfitidea点击:

TextBlock to Display HTML in WPF

wpftextblock

提问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>&nbsp;</div><p>this is the new line&nbsp;<br /><br />second line</p><p>third line</p>";

字符串 html = " <div>hi</div><div>&nbsp;</div><p>this is the new line&nbsp;<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);