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>