title: Communication between ViewModels via events
body: <p>I have an application where I open a new view (with viewmodel) within another viewmodel. The new Viewmodel needs some parameters from the caller viewmodel.</p>
  
  <p>Now I introduced a class called Messenger which looks like:</p>
  
  <pre><code>public class Messenger
      {
          private static Messenger instance;
          public static Messenger Instance
          {
              get { return instance ?? (instance = new Messenger()); }
          }
  
          private Messenger() { }
  
          public void SendMessage(Message message)
          {
              OnMessageSent temp = MessageSent;
              if (temp != null)
                  temp(message);
          }
  
          public delegate void OnMessageSent(Message message);
          public event OnMessageSent MessageSent;
      }
  </code></pre>
  
  <p>The message-class looks like:</p>
  
  <pre><code>public class Message
  {
      public Type TargetType { get; set; }
      public object Sender { get; set; }
      public Type ValueType { get; set; }
      public object Value { get; set; }
      public string AdditionalInfo { get; set; }
  }
  </code></pre>
  
  <p>The usage of this building is:</p>
  
  <p>The receiver-viewmodel of a message has to add </p>
  
  <p><code>Messenger.Instance.MessageSent += MessageSent;</code> </p>
  
  <p>to it's constructor. And in the implementation can look like:</p>
  
  <pre><code> private void MessageSent(Message message)
   {
      if(message.TargetType == typeof(SecondViewModel))
      {
         if (message.ValueType == typeof (double))
            {
               this.MyValue= (double) message.Value;
            }
       }
    }
  </code></pre>
  
  <p>This works fine. My question is: Is this a good way for the communication between viewmodels or are there any weakenings in this design? </p>