How to call javascript function on a Silverlight 3 object?

南楼画角 提交于 2019-12-06 04:43:29

You need to register with Silverlight HTMLBridge an identifier to expose on the Content property and give it an object that has some scriptable entry points.

I tend to do this in the Page constructor:-

public Page()
{
     InitializeComponent();
     HtmlPage.RegisterScriptableObject("Page", this);
}

Now your code should work.

I have this Silverlight application structure:

public partial class App : Application
{
    private void Application_Startup(object sender, StartupEventArgs e)
    {
        Page uploadControl = new Page();
        // ...
        HtmlPage.RegisterScriptableObject("uploadControl", uploadControl);
    }
}

[ScriptableType]
public partial class Page : UserControl
{
    [ScriptableMember]
    public void StartUpload()
    {
        // ...
    }
} 

And, in Javascript:

function startUpload() {
    $find("<%= SilverlightUpload.ClientID %>")
        .get_element().content.uploadControl.StartUpload();
    return false;
}

So, I take a look on that HtmlPage.RegisterScriptableObject call and just expose types marked as [ScriptableType]

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!