这样就会调用BoundObject类的OpenFile方法 CefSharp For WPF响应页面点击事件

时间:2021-09-11 08:15:03

标签:

初始化 <!--浏览器--> <cefSharpWPF:ChromiumWebBrowser Grid.Row="0" > </cefSharpWPF:ChromiumWebBrowser> public MainWindow() { InitializeComponent(); //在js里面注册东西bound,,然后用该东西挪用C#要领 webBrowser.RegisterAsyncJsObject("bound", new BoundObject(this), BindingOptions.DefaultBinder); //Use the default binder to serialize values into complex objects } BoundObject.cs public class BoundObject { private Window mainWindow { get; set; } public BoundObject(Window _mainWindow) { mainWindow = _mainWindow; } /// <summary> /// 打开exe文件 /// </summary> public void OpenFile() { try { //MessageBox.Show("(\"This is an MyMethod coming from C#\")", "haha"); string path ="你要打开的文件目录"; System.Diagnostics.Process.Start(path); } catch(Exception ex) { MessageBox.Show("请输入正确的文件路径!", "提示"); } } } js挪用 bound.openFile();

bound在C#中界说,这样就会挪用BoundObject类的OpenFile要领

CefSharp For WPF响应页面点击事件