title: Mapping derived ViewModels to base class View in Caliburn.Micro
body: <p>I have a base ViewModel and associated View. I also have multiple derived ViewModels from the base ViewModel, but I'd like to use the base View for display.</p>
  
  <p>Base ViewModel and View:</p>
  
  <ul>
  <li>vm: <code>MyCompany.MyApp.Modules.Wizard.ViewModels.WizardViewModel</code></li>
  <li>vw: <code>MyCompany.MyApp.Modules.Wizard.Views.WizardView</code></li>
  </ul>
  
  <p>Derived from <code>WizardViewModel</code>:</p>
  
  <ul>
  <li>vm: <code>MyCompany.MyApp.Modules.NewSpec.ViewModels.NewSpecViewModel : WizardViewModel</code></li>
  <li><p>vw: (map to <code>MyCompany.MyApp.Modules.Wizard.Views.WizardView</code>)</p></li>
  <li><p>vm: <code>MyCompany.MyApp.Modules.NewSpec.ViewModels.NewMaterialViewModel : WizardViewModel</code></p></li>
  <li>vw: (map to <code>MyCompany.MyApp.Modules.Wizard.Views.WizardView</code>)</li>
  </ul>
  
  <p>I think this should be possible using the mapping in <a href="https://caliburnmicro.codeplex.com/wikipage?title=Handling%20Custom%20Conventions&amp;referringTitle=Documentation" rel="noreferrer">ViewLocator or ViewModelLocator</a> or <a href="https://caliburnmicro.codeplex.com/wikipage?title=Using%20the%20NameTransformer" rel="noreferrer">NameTransformer</a>, but I haven't figured it out yet.</p>
  
  <p>I am using the <a href="https://github.com/tgjones/gemini" rel="noreferrer">Gemini Framework</a> with <a href="https://github.com/Caliburn-Micro/Caliburn.Micro" rel="noreferrer">Caliburn.Micro</a> v1.5.2 (I plan on upgrading to v2 soon).</p>
  
  <p>Here is one of the things I have tried:</p>
  
  <pre><code>public class NewSpecViewModel : WizardViewModel
  {
      // ...
      static NewSpecViewModel()
      {
          // Escape the '.' for the regular expression
          string nsSource = typeof(NewSpecViewModel).FullName.Replace(".", @"\.");
          string nsTarget = typeof(WizardViewModel).FullName;
          nsTarget = nsTarget.Replace("WizardViewModel", "Wizard");
          // nsSource = "MyCompany\\.MyApp\\.Modules\\.NewSpec\\.ViewModels\\.NewSpecViewModel"
          // nsTarget = "MyCompany.MyApp.Modules.Wizard.ViewModels.Wizard"
          ViewLocator.AddTypeMapping(nsSource, null, nsTarget);
      }
      // ...
  }
  </code></pre>
  
  <p>P.S. I know there are existing Wizard frameworks (<a href="https://wpftoolkit.codeplex.com/wikipage?title=Wizard&amp;referringTitle=Home" rel="noreferrer">Extended WPF Toolkit</a>, <a href="http://avalonwizard.codeplex.com/" rel="noreferrer">Avalon Wizard</a>, etc), but I don't want to add another 3rd party assembly and the Extended WPF Toolkit Wizard wasn't working properly.</p>
  
  <p>P.P.S. I also want to use this style of base ViewModel/View mapping elsewhere.</p>