简体   繁体   中英

Calling function in WPF from silverlight inside web browser control

I have a WPF application with a web browser control inside which is a silveriight application. Earlier, I have been able to call functions from WPF application to sliverlight application using HTML bridge.

Now, I have to do the opposite to this ie I have to call a function inside the WPF application from silverlight.
How can this be done?

You can do this by using the property as shown below:

C# part :

webBrowserControlName.ObjectForScripting = new ScriptInterface();

where ScriptInterface is as follows

[System.Runtime.InteropServices.ComVisibleAttribute(true)]
public class ScriptInterface
{

    public void CSharpMethod(string data)
    {
        MessageBox.Show(data);
    }
}

HTML part

in the page that you load in the web browser control do the following :

window.External.CSharpMethod('from html page to WPF');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM