title: WPF: switching UserControls depending on corresponding ViewModels (MVVM)
body: <p>I'll try to simplify the task I'm working on by imagining this example:</p>
  
  <p>Let's suppose that we have the following hierarchy of model classes:</p>
  
  <pre><code>Animal
     Lion
     Snake
     Bird
  </code></pre>
  
  <p>...corresponding ViewModels:</p>
  
  <pre><code>AnimalCollectionViewModel
     AnimalViewModel
        LionViewModel
        SnakeViewModel
        BirdViewModel
  </code></pre>
  
  <p>... and corresponding views:</p>
  
  <pre><code>AnimalCollectionView
     LionView
     SnakeView
     BirdView
  </code></pre>
  
  <p>It's supposed that AnimalCollection contains a list filled with objects of different types of animals and below the list it has a property grid for setting the properties of a selected animal. Obviously the property grids will have different properties and should change when the type of a selected item changes.</p>
  
  <p>The question is: How to implement switching of the property grids in WPF according to the MVVM pattern? Using what mechanism?</p>
  
  <p>Currently I have an abstract enum property in the base ViewModel (AnimalViewModel.PropertyGridType = {Lion, Snake, Bird}) which the derived classes implement by returning corresponding values. And the AnimalCollectionView changes the property grid user controls depending on the value of this property. Something like this:</p>
  
  <p>...</p>
  
  <pre><code>&lt;UserControl.Resources&gt;
      &lt;Style x:Key="PropertyGridStyle" TargetType="ContentControl"&gt;
          &lt;Style.Triggers&gt;
              &lt;DataTrigger Binding="{Binding PropertyGridType}" Value="Lion"&gt;
                  &lt;Setter Property="Content"&gt;
                      &lt;Setter.Value&gt;
                          &lt;view:LionPropertyGridView /&gt;
                      &lt;/Setter.Value&gt;
                  &lt;/Setter&gt;
              &lt;/DataTrigger&gt;
              &lt;DataTrigger Binding="{Binding PropertyGridType}" Value="Snake"&gt;
                  &lt;Setter Property="Content"&gt;
                      &lt;Setter.Value&gt;
                          &lt;view:SnakePropertyGridView /&gt;
                      &lt;/Setter.Value&gt;
                  &lt;/Setter&gt;
              &lt;/DataTrigger&gt;
          &lt;/Style.Triggers&gt;
      &lt;/Style&gt;
  &lt;/UserControl.Resources&gt;
  
  &lt;ContentControl Style="{StaticResource PropertyGridStyle}" /&gt;
  </code></pre>
  
  <p>...</p>
  
  <p>But I'm not sure whether it is the right approach. (At least I don't like introducing the auxiliary enum property. Is it possible to deduce the necessary user control based on a ViewModel type?)
  Can anybody advise other options?
  Thanks in advance!</p>