WPF浏览本地html页面,并实现js交互

1.nuget添加cefsharp 

 

声明  
xmlns:wpf="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"

在xaml文件中使用

   <wpf:ChromiumWebBrowser Grid.Row="2" x:Name="webBrowser" Address="www.baidu.com">
                    
    </wpf:ChromiumWebBrowser>

C# 代码中使用
  
this.webBrowser.Address = System.AppDomain.CurrentDomain.BaseDirectory + "Assets/View/chart.html";

C# 调用html中的js方法

            string data = "canshu";
            string info = "fillData('" + data + "')"; //我的JS 方法是initValue
            this.webBrowser.EvaluateScriptAsync(info);

本地HTML文件 

<!DOCTYPE html>

<html lang="zh-cn" xmlns="http://www.w3.org/1999/xhtml">
<!-- saved from url=(0013)about:internet -->
<head>
    <meta charset="utf-8" http-equiv="X-UA-Compatible" content="IE=5,6,7,8,9,10,11, chrome=1" />
    <title>ECharts</title>
</head>

<body>
    <h1>html页面</h1>
    <span id="test">aaa</span>
    <div id="main" style="width:500px;height:500px;margin-left:-8px" />
    <script src="../js/echarts.js"></script>
    <script>myChart = echarts.init(document.getElementById('main'));
        option = {
            xAxis: {
                type: 'category',
                data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
            },
            yAxis: {
                type: 'value'
            },
            series: [{
                data: [820, 932, 901, 934, 1290, 1330, 1320],
                type: 'line'
            }]
        };
        myChart.setOption(option);

        function fillData(data) {
            alert("aaaa")
            //document.getElementById("uname").value = data;
            var oVDiv = document.getElementById("test");
            //oVDiv.setAttribute("vaue", data);
            oVDiv.value = data;

            //oVDiv.value = data;
            //document.write(data);
        }
    </script>
</body>
</html> 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值