title: Let the ViewModel know the generic object of the View
body: <p>I have a generic view where I "inject" some specific view into a contained <code>ContentControl</code> (I created that feature with these help -> <a href="https://stackoverflow.com/q/8987709/1148768">help 1</a> - <a href="https://stackoverflow.com/q/8945930/1148768">help 2</a>).</p>
  
  <p>The basic source of my views are these:</p>
  
  <p><code>MyGenericView.xaml</code></p>
  
  <pre><code>&lt;UserControl x:Class="MyNS.MyGenericView"
               ... &gt;
      &lt;UserControl.Resources&gt;
          &lt;vml:ViewModelLocator x:Key="Locator" d:IsDataSource="True" /&gt;
      &lt;/UserControl.Resources&gt;
      &lt;Grid DataContext="{Binding MyGenericViewModel, Source={StaticResource Locator}}"&gt;
          &lt;ContentControl Content="{Binding MyObject}" /&gt;
      &lt;/Grid&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p><code>CustomerView.xaml</code></p>
  
  <pre><code>&lt;UserControl x:Class="AnotherNS.CustomerView"
               ... &gt;
      &lt;Grid&gt;
          &lt;StackPanel Orientation="Vertical"&gt;
              &lt;Label Content="Description" /&gt;
              &lt;TextBox Text="{Binding description}" /&gt;
          &lt;/StackPanel&gt;
      &lt;/Grid&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p><code>Crud.xaml</code>: a resource dictionary which I use to "solve" what's the correct view to show, depending on the <code>DataType</code> of <code>MyObject</code> object provided by the generic view.</p>
  
  <pre><code>&lt;ResourceDictionary ... &gt;
      &lt;DataTemplate DataType="{x:Type mo:Customer}"&gt;
          &lt;vw:CustomerView /&gt;
      &lt;/DataTemplate&gt;
      &lt;DataTemplate DataType="{x:Type mo:Product}"&gt;
          &lt;vw:ProductView /&gt;
      &lt;/DataTemplate&gt;
      ...
  &lt;/ResourceDictionary&gt;
  </code></pre>
  
  <p>It's working fine. I can manage <code>MyObject</code> through the "specific" view (customer, product, etc).</p>
  
  <p>Well. That's my problem:</p>
  
  <p>All the specific views have their own ViewModels and, of course, they manage the respective views' data. But I don't know (on the viewmodel) what's the object (MyObject) I'm working with, because the Generic View provides it to the Specific View, not to the viewmodel.</p>
  
  <p><strong>Is there a way to let the ViewModels of the specific Views know the object which is "commanding" the view?</strong></p>