Parsing html tags when displaying text in WPF
I just want to parse html tags like those making text bolded etc.
But no real webpages would be displayed in my control. Moreover no editing would be supported, just displaying.
For example for the text content:
abc <b>bold</b> def
I would like to display at my control like this:
abc bold def
What is the best way to parse such an input text and display it ?
Should I use for this WebBrowser control or RichText or TextBlock would sufficient too ?
Do I must to use HtmlDocument or HTMLDocument or FlowDocument or the other one ?
Please let me any suggestion.
Thanks in advance.
You might use a control such as HtmlPanel
or HtmlLabel
from the HtmlRenderer.WPF
package.
https://www.nuget.org/packages/HtmlRenderer.WPF
From their documentation:
<wpf:HtmlPanel Text="<p><h1>Hello</h1> World</p>"/>
With namespace import:
xmlns:wpf="clr-namespace:TheArtOfDev.HtmlRenderer.WPF;assembly=HtmlRenderer.WPF"
If you bind the HTML string, you don't need to escape it. It's only escaped here because it's within the XAML.
More information at:
https://htmlrenderer.codeplex.com/
链接地址: http://www.djcxy.com/p/50524.html上一篇: 通过Gmail SMTP服务器使用C#发送电子邮件
下一篇: 在WPF中显示文本时解析html标签