title: Implementing WPF MVVM Dialog Service
body: <p>I'm trying to implement the "MVVM recommended" way of handling multiple views/windows in the application thru a DialogService. However, I encountered a difficulty in implementing closing the parent view after showing the child view. Here's my implementation so far. What is the best strategy for WPF MVVM to handle such scenario?</p>
  
  <p>DialogService.cs (I try to make this generic so that it can show and close any windows)</p>
  
  <pre><code>public class DialogService : IDialogService
  {
      /// &lt;summary&gt;
      /// Closes the specified window screen
      /// &lt;/summary&gt;
      /// &lt;param name="dialogWindow"&gt;&lt;/param&gt;
      public void CloseDialog(Window dialogWindow)
      {
          if ( dialogWindow != null )
              dialogWindow.Close ( );       
      }
  
      /// &lt;summary&gt;
      /// Shows the specified window screen
      /// &lt;/summary&gt;
      /// &lt;param name="dialogWindow"&gt;&lt;/param&gt;
      public void ShowDialog(Window dialogWindow)
      {
          if ( dialogWindow != null )
              dialogWindow.ShowDialog ( );
      }
  }
  </code></pre>
  
  <p>The view model that shows the child view is SelectPackageViewModel.cs</p>
  
  <pre><code>public SelectPackageViewModel(IPackageDataService packageDataService, IDialogService dialogService)
  {
      this.packageDataService = packageDataService;
      this.dialogService = dialogService;
      LoadPackages();
      LoadCommands();
  }
  private void LoadCommands()
  {
      CreateNewCommand = new CustomCommand(CreateNewPackage);
  }
  private void CreateNewPackage(object obj)
  {            
      dialogService.ShowDialog(new CreatePackage());            
  }
  </code></pre>
  
  <p>The parent view SelectPackage.cs. The child view is CreatePackage.cs</p>
  
  <pre><code>&lt;Button Name="btnNewPackage"
      Content="New..."
      HorizontalAlignment="Center"
      Width="120"
      Height="30"
      FontSize="15" FontWeight="Bold"
      Margin="10"
      Command="{Binding CreateNewCommand}"/&gt;
  </code></pre>