Thursday, June 24, 2010

Interaction between two XAP's in silverlight!

In many of the cases we need to communicate between the XAP's internally.Suppose if we want to use reuse silverlight application then we have to make it available for communicate.

So, In this way if one xap file wants to communicate with other xap file, have to use javascript to invoke communication.


1.Step:Registering managed object using RegisterScriptableObject.

HtmlPage.RegisterScriptableObject("ARV", this);
this ARV name will be used on later with javascript.

Invoking javascript function from silverlight.
HtmlPage.Window.Invoke("TalkToJavaScript", "Hello from Silverlight");

2.Step:

C# method to get value from previous XAP.

[ScriptableMember]

public void UpdateText(string result)

{

myTextbox.Text = result;

}


3.Step: javascript function.



function TalkToJavaScript( data)

{

alert("Message received from Silverlight: "+data);



var control = document.getElementById("silverlightControl");

control.Content.Page.UpdateText("Hello from Javascript!");

}




Mail To:aravindbenator@gmail.com

No comments:

Post a Comment