参考资料:
https://www.jianshu.com/p/039dc834b2b9;
https://zhuanlan.zhihu.com/p/102688922
方法1 :使用【WebBrowser】,能加载大部分网页
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
<wf:WebBrowser x:Name="samlogin"></wf:WebBrowser>
方法2 :使用【ChromiumWebBrowser】,比方法1兼容性强,方法1不能正常预览的网站就尝试方法2(例如,WebGL)
xmlns:wpf="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
<wpf:ChromiumWebBrowser x:Name="samlogin" Address="http://www.baidu.com" />
ChromiumWebBrowser的交互方法:
html端: CefSharp.PostMessage(‘需要传递到WPF程序的信息’);
WPF端:
samlogin.JavascriptMessageReceived += Samlogin_JavascriptMessageReceived; private void Samlogin_JavascriptMessageReceived(object sender, JavascriptMessageReceivedEventArgs e) { try { var dddd = (string)e.Message; log.Error($"获取到Web传递的数据信息:{dddd}"); } catch (Exception ex) { throw; } }
标签:JavascriptMessageReceived,网页,CefSharp,WPF,方法,加载 From: https://www.cnblogs.com/lhlong/p/17240244.html