zoukankan      html  css  js  c++  java
  • WPF中展示HTML

    Winform的WebBrowser相对灵活一些。接下来把操作步骤分享给大家。

    一、  引入dll

    System.Windows.Forms.dll和WindowsFormsIntegration.dll。

    两个都是.NET框架下的dll,不需要额外下载。

     

    二、  向界面中添加定义的控件(将导入的dll引入到界面中啦)。Xaml代码部分:

    xmlns:wf ="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"

    xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"

     

    //插入Winform的WebBrowser控件

      <wfi:WindowsFormsHost Name="winFormsContainer">

      <wf:WebBrowser x:Name="webBrowser1"/>

      </wfi:WindowsFormsHost>

    注意:只有在WindowsFormsHost标签下才能插入WinForm控件。当然你也可以插入其他WinForm控件

     

     三、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样式(真的很方便!)

  • 相关阅读:
    Pycharm 2016 注册码
    在mac上搭建python环境
    Carthage 的使用
    生成唯一的随机字符串
    utf-8 转码--网址转码
    让自己的项目支持 Carthage
    系统自带的语音合成
    个性化 UIAlertController
    cocoaPods 创建自己的依赖库
    appleDoc 使用
  • 原文地址:https://www.cnblogs.com/xuhongfei/p/8929891.html
Copyright © 2011-2022 走看看