title: How to launch multiple independent windows using a DialogService in MVVM?
body: <p>In MVVM fashion, I have an initial window opening (MainView) with its DataContext (i.e., its viewmodel) being initialized from the code-behind:</p>
  
  <p>XAML:</p>
  
  <pre><code>&lt;Window x:Class="Nova5.UI.Views.MainView"    ..............
  </code></pre>
  
  <p>Code-Behind C#:</p>
  
  <pre><code>public partial class MainView : Window
  {
      private MainViewModel vm = new MainViewModel(new WPFMessageBoxService());
  
      public MainView()
      {
          InitializeComponent();
  
          this.Loaded += (s, e) =&gt; { this.DataContext = this.vm; };
  
      }
  
  
  }
  </code></pre>
  
  <p>From there on out, I use a DialogService  to open other windows from  UserControls:</p>
  
  <p>XAML:</p>
  
  <pre><code>&lt;Window x:Class="Nova5.UI.Views.WindowDialog"
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              Title="WindowDialog" 
              WindowStyle="SingleBorderWindow" 
              WindowStartupLocation="Manual" SizeToContent="WidthAndHeight"&gt;
  
      &lt;ContentPresenter x:Name="DialogPresenter" Content="{Binding .}"/&gt;
  
  &lt;/Window&gt; 
  </code></pre>
  
  <p>The ViewModel creates the WindowDialog and associated viewmodel and opens the window. </p>
  
  <p>All is good.</p>
  
  <p>Now the problem. Lets say I have ten usercontrols. Each of these UserControls can be presented by the DialogService. Each of these UserControls can open other UserControls.  </p>
  
  <p>What I would like to do is have the MainWindow open UserControl_1. Then have UserControl_1 open UserControl_2. UserControl_1 then needs to close leaving UserControl_2 open. Ofcourse, UserControl_2 can open UserControl_3 after which UserControl_2 disappears leaving only the MainWindow and UserControl_3. In short, each launched UserControl needs to be independent of the control that created it.</p>
  
  <p>I hope this is understandable.</p>
  
  <p>How can this be done?   Thanks for any ideas or help.</p>