title: What is the best way to deal with dialogs in a ViewModel?
body: <p><strong>Following-up on the IDialogService approach:</strong></p>
  
  <p>What about the <code>System.Windows.MessageBoxResult</code> enum? Is the better approach to keep it out of the interface and only involve it in the implementation?</p>
  
  <p><strong>Approach I chose for the <code>System.Windows.MessageBoxResult</code> enum</strong>:</p>
  
  <p>I added an enum next to the IDialogInterface that covers Yes, NO, Ok, Cancel:</p>
  
  <pre><code>namespace Foo.Bar.Dialogs
  {
      public enum DialogResult { Ok, Yes, No, Cancel }
  
      public interface IDialogService
      {
          void ShowErrorBox(string error_message);
  
          DialogResult ShowQuestionBox(string question_message);
  
          DialogResult ShowQuestionBox(string question_message, string caption);
  
          DialogResult ShowQuestionBox(string question_message, string caption, bool allow_cancel);
  
          DialogResult ShowQuestionBox(string question_message, string caption, bool allow_cancel, bool show_as_error);
  
          void ShowWarningBox(string message, string caption = "");
  
          void ShowInformationBox(string message);
  
          void ShowInformationBox(string message, string caption);
      }
  }
  </code></pre>
  
  <p><strong>Initial question:</strong></p>
  
  <p>I am working on moving all the commands from my .asmx.cs file to the ViewModel of the main window of some application.</p>
  
  <p>Now I have to figure out what to do with commands that ask for confirmation(s) from the user.</p>
  
  <p><em>For now</em> I'll just suck in the necessary types in my ViewModel to launch my dialog boxes directly. I'm pretty sure this is not the best or <em>cleanest</em> way to do this.</p>
  
  <p>I found this <a href="http://andrewtokeley.net/archive/2010/07/25/mvvm-and-confirmation-dialogs.aspx" rel="nofollow">article</a> with an interesting and cleaner approach. It uses an IDialogService interface:</p>
  
  <pre><code>public interface IDialogService
  {
      int Width { get; set; }
      int Height { get; set; }
      void Show(string title, string message, Action&lt;DialogResult&gt; onClosedCallback);
  }
  </code></pre>
  
  <p>I also found this <a href="http://code.msdn.microsoft.com/How-to-implement-MVVM-71a65441" rel="nofollow">article</a> which seems even better as it checks if the IDialogInterface is null before trying to use it:</p>
  
  <pre><code>private void PerformAddNewCustomer() 
  { 
      CustomerList.Add(new Customer { Name = "Name" + i }); 
      i++; 
  
      if (dialogService != null) 
      { 
          dialogService.Show("Customed added"); 
      } 
  } 
  </code></pre>
  
  <p>Is this the best way to separate dialogs from the ViewModel, or is there an even better approach?</p>