Cefsharp for WPF response page click events

Source: Internet
Author: User

Initialization
<!--浏览器--><cefSharpWPF:ChromiumWebBrowser Name="webBrowser"                                 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 Call
bound.openFile();

Bound is defined in C # so that the OpenFile method of the Boundobject class is called

Cefsharp for WPF response page click events

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.