Side managed code, Silverlight provides HtmlPage class that allows interaction between Silverlight and the page. Interaction contrary, then by Javascript code to managed code, but must be prepared in a manner a little more detail. First, within the Silverlight Loaded event to be recorded by the object which then can be made to the communication from the page.
This registration is done by calling RegisterScriptableObject, always the class HtmlPage:
Code:
private void UserControl_Loaded (object sender, RoutedEventArgs e)
{
HtmlPage.RegisterScriptableObject (SilverlightToJavascriptControlObject ", this);
}
We note that the key choice is entirely arbitrary. Then instead, we must choose the method that we want to be callable from JavaScript and decorate it with the attribute "ScriptableMember.
Code:
[ScriptableMember]
public void AddItem (string value)
{
listbox.Items.Add (value);
HtmlPage.Window.Alert ("called from javascript");
}
Bookmarks