WPF WebBrowser控件解析 HTML

WPF WebBrowser控件解析 HTML

xml 复制代码
Window里面的AllowsTransparency属性不要加
xml 复制代码
<WebBrowser x:Name="webBrowser"  />
csharp 复制代码
public void InitWeb()
{
   string htmlString = @"<html>
    <head>
        <title>this is a test</title>
        <script type ='text/javascript'>
            function Hello()
            {
                window.external.Hello('hello test'); // 传递事件
            }
        </script>
    </head>
    <body>
        <button onclick = 'Hello()'>
            hello test
        </button>
    </body>
</html> ";
            webBrowser.NavigateToString(htmlString);


            ObjectForScriptingHelper helper = new ObjectForScriptingHelper(this);
            webBrowser.ObjectForScripting = helper;
}
csharp 复制代码
    [System.Runtime.InteropServices.ComVisibleAttribute(true)]//将该类设置为com可访问
    public class ObjectForScriptingHelper
    {
        signature mainWindow;

        public ObjectForScriptingHelper(signature main) // 注意signature 要写成你自己项目中的对象名
        {
            mainWindow = main;
        }

        //这个方法就是网页上要访问的方法
        public void Hello(string cmd)
        {
        }
    }
相关推荐
aini_lovee5 小时前
33节点配电网分布式发电(DG)最优分布MATLAB实现
分布式·matlab·wpf
czhc11400756636 小时前
wpf 28
wpf
baivfhpwxf20236 小时前
WPF Binding 绑定 超详细详解
c#·wpf
极客小俊6 小时前
【H5 前端开发笔记】第 03 期:HTML的历史、书写规范与文档类型声明<!DOCTYPE> 详解
html·学习笔记·前端开发·编程基础·免费教程·html文档类型声明·零基础学习
像风一样的男人@7 小时前
python --html转pdf/pdf分页优化
python·pdf·html
Never_Satisfied7 小时前
在JavaScript / HTML中,获取指定元素的父元素
开发语言·javascript·html
数据知道7 小时前
MongoDB心跳检测与故障转移:自动主从切换的全过程解析
数据库·mongodb·wpf
anOnion3 天前
构建无障碍组件之Switch Pattern
前端·html·交互设计
willow9 天前
html5基础整理
html