Winform的WebBrowser相对灵活一些。接下来把操做步骤分享给你们。css
1、 引入dllhtml
System.Windows.Forms.dll和WindowsFormsIntegration.dll。web
两个都是.NET框架下的dll,不须要额外下载。框架
2、 向界面中添加定义的控件(将导入的dll引入到界面中啦)。Xaml代码部分:spa
xmlns:wf ="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"orm
xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"xml
//插入Winform的WebBrowser控件htm
<wfi:WindowsFormsHost Name="winFormsContainer">string
<wf:WebBrowser x:Name="webBrowser1"/>it
</wfi:WindowsFormsHost>
注意:只有在WindowsFormsHost标签下才能插入WinForm控件。固然你也能够插入其余WinForm控件
3、cs代码段
string html=“你须要展现的html代码”;
//调用引入的webBrowser1
webBrowser1.Navigate("about:blank"); //必定要建立一个空白界面。否则即便写入html成功显示也不能再次回读其中内容。
webBrowser1.Document.OpenNew(false);
webBrowser1.Document.Write(html);
webBrowser1.Refresh();
//这个时候你能够写js代码来操纵你想要的一切(以下)
String newContent = webBrowser1.Document.GetElementById("container").InnerHtml;
//也能够webBrowser写入html时加入一些css样式(真的很方便!)