在C#中呈现HTML标记

时间:2013-04-21 00:37:39

标签: c# html wpf rendering

是否有一个易于使用的库或其他方法,我可以将HTML作为字符串传递(使用< table>或< div>等标签),然后应用程序将正确显示它屏幕?

到目前为止,我只发现了HTML Agility Pack,但它似乎并不是非常友好的。

一个例子:

submitted by <a href="http://www.reddit.com/user/kiransran"> kiransran </a> 
to <a href="http://www.reddit.com/r/news/"> news</a> 
<br/> 
<a href="http://imgur.com/GtDN6rz">[link]</a> 
<a href="http://www.reddit.com/r/news/comments/1cretq/infrared_image_of_boston_marathon_suspect_hiding/">[976 comments]</a>

来自RSS Feed。我需要在WPF中显示结果

3 个答案:

答案 0 :(得分:1)

如果您只想渲染它,请使用网络浏览器控件:

<WebBrowser HorizontalAlignment="Left" Height="203" VerticalAlignment="Top" Width="335" Margin="46,52,0,0" Name="wb1"/>

然后调用NavigateToString方法:

string s = @"<html><body>Hello <b>World</b></body></html>";
wb1.NavigateToString(s);

答案 1 :(得分:0)

使用字符串操作来提取感兴趣的html start&amp;完成,包装并使用浏览器控件显示它:

http://www.c-sharpcorner.com/uploadfile/rahul4_saxena/webbrowser-control-in-wpf/

字符串操作API无论如何都要学习,如果你只是想显示HTML,那么你只需要为浏览器控件提供合适的html。

您可能首先需要WebRequest来获取RSS,但您还没有问过这个问题。

答案 2 :(得分:0)

看看Geckofx:

http://code.google.com/p/geckofx/

但是如果你想要你可以使用Webbrowser控件,但请记住那只是IE。

相关问题