title: Can a Window (of WPF) know whether it is opened by ShowDialog()?
body: <p>Can a <code>Window(System.Windows)</code> know whether it is opened by <code>Show()</code> or <code>ShowDialog()</code>?</p>
  
  <p>If <code>DialogResult</code> is set on a window which is opened by <code>Show()</code> method,
  it throws an <code>InvalidOperationException</code>(<a href="http://msdn.microsoft.com/en-us/library/system.windows.window.dialogresult(v=vs.110).aspx" rel="nofollow">MSDN</a>).</p>
  
  <p>Is there any way to know how the window is opened and to avoid it?
  Should I use <code>try-catch</code>?</p>
  
  <pre><code>public partial class Window1 : Window {
      public Window1() {
          InitializeComponent();
      }
  
      private void CancelButton_OnClick([NotNull] object sender, [NotNull] RoutedEventArgs e) {
          DialogResult = false; // throws an InvalidOperationException.
      }
  }
  </code></pre>