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)
        {
        }
    }
相关推荐
分布式存储与RustFS2 小时前
告别复杂配置:用Milvus、RustFS和Vibe Coding,60分钟DIY专属Chatbot
wpf·文件系统·milvus·对象存储·minio·rustfs·vibe
深蓝电商API8 小时前
网页结构解析入门:HTML、CSS、JS 与爬虫的关系
javascript·css·html
曦曜29211 小时前
聊聊前端静态页面的开发
css·html
攻城狮CSU14 小时前
WPF 绑定机制实现原理
wpf
攻城狮CSU14 小时前
WPF 之数据绑定一(Data Binding)
wpf
立方世界14 小时前
HTML编写规则及性能优化深度解析:从基础到企业级实践
前端·性能优化·html
_小许_1 天前
Go语言实现HTML转PDF
golang·pdf·html
wuty0071 天前
记录一下 WPF进程 SendMessage 发送窗口消息进行进程间通信,存在进程权限无法接受消息的问题
wpf·进程间通信·sendmessage·进程权限
少年阿闯~~1 天前
解决HTML塌陷的方法
前端·html
雨过天晴而后无语1 天前
Windchill中MVC选中事件级联另一MVC内容
java·javascript·html·mvc