title: How to get data into the ViewModel of a UserControl?
body: <p>New to WPF/MVVM. I have a data object of type "MyData". One of its properties is of type "MySubsetData".</p>
  
  <p>I show a collection of "MyData" objects in a datagrid.</p>
  
  <pre><code>&lt;DataGrid ItemsSource="{Binding Path=MyDataCollection}"&gt;
      &lt;!-- Each row of the datagrid contains an item of type "MyData" --&gt;
      &lt;DataGrid.Columns .../&gt;
      &lt;DataGrid.RowDetailsTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;local:MySubsetDataUserControl/&gt;
          &lt;/DataTemplate&gt;
      &lt;/DataGrid.RowDetailsTemplate&gt;
  &lt;/DataGrid&gt;
  </code></pre>
  
  <p>The row details should show the content of "MySubsetData". The view of the row details is in a separate user control (here: "MySubsetDataUserControl").</p>
  
  <p>At the moment I don't set a view model for "MySubsetDataUserControl", so it inherits the data context from the parent's datagrid row.</p>
  
  <pre><code>&lt;UserControl&gt;
      &lt;!-- Namespace stuff not shown for simplicity --&gt;
      &lt;Grid DataContext="{Binding Path=MySubsetData}"&gt;
          &lt;!-- Show the MySubsetData properties here --&gt;
          &lt;!-- e.g. a textbox --&gt;
              &lt;TextBox Text="{Binding Path=TextData, UpdateSourceTrigger=PropertyChanged}"/&gt;
      &lt;/Grid&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>Altough this is working I face several problems with this approach:</p>
  
  <ol>
  <li><p>All business logic will be in the user control parent's view model, where it simply doesn't belong. Making the view model messier than it need to be. Not to mention that command bindings in the user controls xaml look very ugly as well. It just doesn't feel right.</p></li>
  <li><p>As more row details could be visible at the same time, I can't bind the properties of "MySubsetData" to an observable property in the view model. I.e. if I change a property in code (e.g. TextData) the change will not be reflected in the view. My workaround is not to alter the property "TextData". Instead I change the content of the textbox Text property, which in turn will update the "TextData" property. And that feels very wrong!</p></li>
  </ol>
  
  <p>So I would like to use another view model for my user control, but I don't know how to access my data then.</p>
  
  <pre><code>&lt;UserControl.DataContext&gt;
      &lt;local:UserControlViewModel/&gt;
  &lt;/UserControl.DataContext&gt;
  </code></pre>
  
  <p>How do I access "MySubsetData" now?</p>