Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do oob silverlight application communicate through windows

If I have two windows in an oob application how do I communicate between them?

This is the new feature of silverlight 5 that allows for multiple windows.

like image 213
zachary Avatar asked Dec 17 '25 10:12

zachary


1 Answers

They run in a common application. Hence they share the same static data. The scope of communication choices are therefore very large. Here is an example:-

public class MessageEventArgs : EventArgs
{
      public MessageEventArgs(object payload)
      {
           Payload = payload;
      }

      public object Payload {get; private set; }
}

public class Messenger
{
    private static readonly Messenger _current = new Messenger();
    public static Messenger Current { get { return _current; } }

    public event EventHandler<MessageEventArgs> MessageReceived;

    public void Send(object payload)
    {
          if (MessageReceived != null)
               MessageReceived(this, new MessageEventArgs(payload));
    }
}

All windows can attach a handler to Messenger.Current.MessageReceived (just be sure to detach when the window closes) and any window can call Messenger.Current.Send.

Ok so you wouldn't actually use this code its a bit rubbish, the point is Windows in SL5 are not isolated. You can create whatever internal application communication mechanism you need.

like image 172
AnthonyWJones Avatar answered Dec 20 '25 02:12

AnthonyWJones



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!