title: DialogResult WPF
body: <p>I am reading one book which says  </p>
  
  <blockquote>
    <p>Rather than setting the DialogResult
    by  hand after the user clicks a
    button, you can designate a button as
    the accept button (by setting
    IsDefault to true). Clicking that
    button automatically sets the
    DialogResult of the window to true.
    Similarly, you can designate a button
    as the cancel button (by setting
    IsCancel to true),  in which case
    clicking it will set the DialogResult
    to Cancel.</p>
  </blockquote>
  
  <p>This is the MainWindow:</p>
  
  <pre><code>&lt;Window x:Class="WpfApplicationWPF.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="MainWindow" Width="400" Height="400"&gt;
      &lt;StackPanel&gt;
  
          &lt;Button Name="BtnShowDialogStatus" Click="BtnShowDialogStatus_Click"&gt;DIALOG RESULT&lt;/Button&gt;
      &lt;/StackPanel&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>Code for click event:  </p>
  
  <pre><code>private void BtnShowDialogStatus_Click(object sender, RoutedEventArgs e)
  {
      MessageBox.Show(new NewWindow().ShowDialog().ToString());
  }
  </code></pre>
  
  <p>And this is the Dialog box which I am opening on the click event:  </p>
  
  <pre><code>&lt;Window x:Class="WpfApplicationWPF.NewWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="NewWindow" Height="300" Width="300"&gt;
      &lt;StackPanel&gt;
          &lt;Button Name="BtnDEfault" IsDefault="True" Click="BtnDEfault_Click"&gt;DEFAULT BUTTON&lt;/Button&gt;
          &lt;Button Name="BtnCancel" IsCancel="True" Click="BtnCancel_Click"&gt;CANCEL BUTTON&lt;/Button&gt;
      &lt;/StackPanel&gt;
  &lt;/Window&gt;   
  </code></pre>
  
  <p>This is the code for it:  </p>
  
  <pre><code>private void BtnDEfault_Click(object sender, RoutedEventArgs e)
  {
      this.Close();
  }
  
  private void BtnCancel_Click(object sender, RoutedEventArgs e)
  {
      this.Close();
  }
  </code></pre>
  
  <p>I can see it returning the DialogResult only as false no matter I click the default or cancel button.  </p>