Communicate with different Silverlight Application in the browser

1. Create two Silverlight Applications which are sharing the same asp.net application. When rebuilt the two SL application, the *.xap files will be generated to the folder ./ClientBin

 

2. Imported the two Silverlight xap to the same asp.net or html page.

 

3. In the two SilverLight Applications add the namespace "using System.Windows.Messaging;"

 

4. In the first SL application, which we call it sender, add the following code accordingly.

LocalMessageSender msgSender = new LocalMessageSender("MyReceiver"); // the para is the message receiver name private void btnSubmit_Click(object sender, RoutedEventArgs e) { msgSender.SendAsync("this message from the first app"); }

 

5. In the second SL application, which we call it Receiver, add the following code accordingly.

// in the pageload event. LocalMessageReceiver receiver = new LocalMessageReceiver("MyReceiver"); receiver.MessageReceived += new EventHandler<MessageReceivedEventArgs>(receiver_MessageReceived); receiver.Listen(); void receiver_MessageReceived(object sender, MessageReceivedEventArgs e) { tbContent.Text = e.Message; }

 

when we run the application, and click the button in the first application, the message will be displayed in the second Silverlight application.

你可能感兴趣的:(Communicate with different Silverlight Application in the browser)