title: MVVM (with WPF) - Binding Multiple Views to the Same ViewModel
body: <p>I have recently started investigating the MVVM pattern with WPF for an upcoming project. I started with <a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx" rel="noreferrer">Josh Smith's MSDN article.</a> I have a question (well many, but let's start with one):</p>
  
  <p>I have an IndividualViewModel which exposes the properties of the model. I need two views "Add Individual" and "Edit Individual" which are very similar as you can imagine. What I have done currently is to have 2 subclasses AddIndividualViewModel and EditIndividualViewModel which expose the Add and Edit commands respectively. I also have 2 similary named views that bind to these.</p>
  
  <p>Now this method works and these classes are fairly small anyway, but I'm wondering if it is possible for me to have just the one view model, which exposes both commands. I would still have 2 views which would bind to this same view model, exposing the appropriate command as a button. I'm not quite sure how to do this. In the main window resources I have something like:</p>
  
  <pre><code>        &lt;DataTemplate DataType="{x:Type ViewModels:AddIndividualViewModel}"&gt;
              &lt;Views:AddIndividualView /&gt;
          &lt;/DataTemplate&gt;
  </code></pre>
  
  <p>With this method of binding you can only have a one-to-one binding, i.e. the same view is always shown for a given view model. Is there a way to automatically switch the view depending on a property on the view model (e.g. IndividualViewModel.Mode). Is there a different approach I should be considering?</p>
  
  <p>Note that the main window has a collection of view models and shows each in tab.</p>
  
  <p>Thank you!</p>