title: Display two WPF windows simultaneously using Caliburn.Micro
body: <p>I have a need to display two WPF controls at one time, in separate windows, at startup.  The parent windows are of the same type and the user controls (and parent window) are defined in a separate assembly, which is only referenced by the host project.  I am using Caliburn.Micro as an MVVM framework and Ninject for IoC.  How can this be done?</p>
  
  <p>All viewmodels are derived from PropertyChangedBase.  I have already setup AppBootstrapper to define the Caliburn.Micro standard bindings, such as WindowManager:</p>
  
  <pre><code>  _kernel.Bind&lt;IControl1&gt;().To&lt;Control1ViewModel&gt;().InSingletonScope();
    _kernel.Bind&lt;IControl2&gt;().To&lt;Control2ViewModel&gt;().InSingletonScope();
    _kernel.Bind&lt;IParentWindow&gt;().To&lt;ParentWindowViewModel&gt;();
  </code></pre>
  
  <p>and created an override for OnStartup that created Control1:</p>
  
  <pre><code>DisplayRootViewFor&lt;IWindow1&gt;();
  </code></pre>
  
  <p>The user control is supplied to the parent window in a ContentControl as a window context, like this: </p>
  
  <pre><code>&lt;ContentControl x:Name="WindowView"
       HorizontalAlignment="Stretch"
       VerticalAlignment="Stretch"
       cal:View.Context="{Binding ViewContext}"
       cal:View.Model="{Binding WindowContent}" /&gt;
  </code></pre>
  
  <p>Finally, I also provided an override to SelectAssemblies, so that Caliburn.Micro could find the views and viewmodels in the dll:</p>
  
  <pre><code>protected override IEnumerable&lt;Assembly&gt; SelectAssemblies()
  {
      var assemblies = base.SelectAssemblies().ToList();
      assemblies.Add(typeof(IControl1).GetTypeInfo().Assembly);
      return assemblies;
  }
  </code></pre>
  
  <p>I have tried several possible solutions, none of which worked:</p>
  
  <ol>
  <li><p>Open the Window2 from the constructor of the Window1 viewmodel (using WindowManager.ShowWindow).  However, this only opened Window2, and never opened Window1.  Probably not a good idea anyway..</p></li>
  <li><p>Create one window in AppBootstrapper.OnStartup, and another window using the App.xaml StartupUri, however this did not allow me to include the user control inside a generic parent window.  All I could do was open an empty parent window.</p></li>
  <li><p>Call DisplayRootViewFor() on the interface for each window to open on startup.  The problem with this is there is no way to set the window content, so you don’t get the custom parent window, just the default window provided by Caliburn.Micro.</p></li>
  </ol>