title: MVVM Pattern, ViewModel DataContext question
body: <p>I need to figure out how to communicate between ViewModels. I'm new to MVVM so please be kind.</p>
  
  <p>Here's a dumbed down example</p>
  
  <p>class definitions(assume that I have hooked the Child.PropertyChanged event in the ParentViewModel):</p>
  
  <pre><code>public class ParentViewModel : ViewModelBase
  {
      public ChildViewModel Child { get; set; }
  }
  
  public class ChildViewModel : ViewModelBase
  {
      String _FirstName;
      public String FirstName 
      {
          get { return _FirstName; }
          set
          {
              _FirstName = value;
              OnPropertyChanged("FirstName");
          }
      }
  }
  </code></pre>
  
  <p>Here's what you see in the resource dictionary</p>
  
  <pre><code>&lt;DataTemplate DataType="{x:Type vm:ParentViewModel}"&gt;
      &lt;vw:ParentView/&gt;
  &lt;/DataTemplate&gt;
  
  &lt;DataTemplate DataType="{x:Type vm:ChildViewModel}"&gt;
      &lt;vw:ChildView/&gt;
  &lt;/DataTemplate&gt;
  </code></pre>
  
  <p>and the code-behind of the ChildView:</p>
  
  <pre><code>public partial class ChildView : UserControl
  {
      public QueueView()
      {
          InitializeComponent();
          DataContext = new ChildViewModel();
      }
  }
  </code></pre>
  
  <p>The obvious problem is that when the ChildView gets instantiated (via selection from the DataTemplate) it creates a new ChildViewModel class and the ParentViewModel doesn't have access to it.</p>
  
  <p>So how can I instantiate the DataContext of the View to be the original ViewModel that caused the DataTemplate to be selected?</p>
  
  <p>An obvious fix is to mmerge the properties in the ChildViewModel into the ParentViewModel, but I would rather separate it because for reuse.</p>
  
  <p>I'm sure the answer is trivial, I just would like to know what it is. :)</p>
  
  <p>Thanks in advance.</p>