title: How do I launch a non-modal dialog in MVVM?
body: <p>I have a C# application designed using MVVM. The structure is conventional.</p>
  
  <p>I have a view model where I would like to launch a custom non-modal dialog.</p>
  
  <p>This dialog is responsible for collecting a data bound serial number.</p>
  
  <p>Here is how I imagine my non-modal dialog:</p>
  
  <p><a href="https://i.stack.imgur.com/kgOlw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kgOlw.png" alt="enter image description here"></a></p>
  
  <p>Here is the Xaml code:</p>
  
  <pre><code>&lt;Window x:Class="RailComm.EmbeddedApplications.EacManagementTool.Views.RestoreDeviceDialogView"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:local="clr-namespace:RailComm.EmbeddedApplications.EacManagementTool.Views"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
          Title="Device Restore" Height="150" Width="375"&gt;
          &lt;Window.Resources&gt;
              &lt;Style TargetType="{x:Type TextBox}" x:Key="SelectableLabel"&gt;
                  &lt;Setter Property="BorderThickness" Value="0" /&gt;
                  &lt;Setter Property="Background" Value="Transparent" /&gt;
                  &lt;Setter Property="IsReadOnly" Value="True" /&gt;
                  &lt;Setter Property="HorizontalAlignment" Value="Center" /&gt;
              &lt;/Style&gt;
          &lt;/Window.Resources&gt;
          &lt;Grid&gt;
              &lt;Grid.RowDefinitions&gt;
                  &lt;RowDefinition Height="*"/&gt;
                  &lt;RowDefinition Height="*"/&gt;
                  &lt;RowDefinition Height="*"/&gt;
                  &lt;RowDefinition Height="35"/&gt;
              &lt;/Grid.RowDefinitions&gt;
              &lt;StackPanel Grid.Row="0"&gt;
                  &lt;Label HorizontalAlignment="Left" Grid.Row="1"&gt;This device has no identity, would you like to restore it?&lt;/Label&gt;
              &lt;/StackPanel&gt;
              &lt;StackPanel Grid.Row="1"&gt;
                  &lt;UniformGrid Rows="1" Columns="2" &gt;
                      &lt;Label HorizontalAlignment="Right"&gt;Device IP:&lt;/Label&gt;
                      &lt;TextBox Text="{Binding IpAddress, Mode=OneWay}" Style="{StaticResource SelectableLabel}"&gt;&lt;/TextBox&gt;
                  &lt;/UniformGrid&gt;
              &lt;/StackPanel&gt;
              &lt;StackPanel Grid.Row="2"&gt;
                  &lt;UniformGrid Rows="1" Columns="2" &gt;
                      &lt;Label HorizontalAlignment="Right"&gt;Serial Number:&lt;/Label&gt;
                      &lt;TextBox Text="{Binding SerialNumber, Mode=TwoWay}"&gt;&lt;/TextBox&gt;
                  &lt;/UniformGrid&gt;
              &lt;/StackPanel&gt;
              &lt;DockPanel Grid.Row="3"&gt;
                  &lt;StackPanel Orientation="Horizontal" FlowDirection="RightToLeft" Margin="5"&gt;
                      &lt;Button Content="No" Command="{Binding CancelCommand }" Width="45"/&gt;
                      &lt;Separator Width="5"/&gt;
                      &lt;Button Content="Identify" Command="{Binding IdentifyCommand }"/&gt;
                      &lt;Separator/&gt;
                  &lt;/StackPanel&gt;
              &lt;/DockPanel&gt;
          &lt;/Grid&gt;
      &lt;/Window&gt;
  </code></pre>
  
  <p>Now I would like to hook this into my existing view model, which also contains other view models as properties.</p>
  
  <p>The view model I'd like to add this too, has a method called <code>GetUpdate()</code>. At a certain point in the method I'd like to display the non-modal dialog to the user. If the serial number passes a check I'll except the result and close the dialog. If the serial number fails I'd like to display an error in the same dialog.</p>
  
  <p>I plan on having these files:</p>
  
  <pre><code>ExistingViewModel.cs
  DialogViewModel.cs
  DialogView.xaml
  </code></pre>
  
  <p>I just don't know how to hook them up. Displaying this model asynchronously is very important to me. I would likely run the dialog in a <code>Task.Rush()</code>..</p>
  
  <p>This dialog does not update the parent view. This dialog just get the value to pass to another method.</p>
  
  <p>How can I implement this? I've seen other peoples approaches but they don't make sense for my implementation. They don't show/explain how the view and the view models are connected. They often leave things out or chunks of code that don't have a home, e.g. this code should go into this class... </p>
  
  <p>Major thanks to anyone who can get me on the right track with this!</p>