title: ShowDialog() ends prematurely if called from hidden windows
body: <p>Consider this code:</p>
  
  <pre><code>public partial class MainWindow : Window
  {
      public MainWindow()
      {
          InitializeComponent();
          Title = DateTime.Now.ToString();
      }
  
      private void Button_Click(object sender, RoutedEventArgs e)
      {
          Hide();
          new MainWindow().ShowDialog();
          Show();
          Debug.WriteLine(Title);
      }
  }
  </code></pre>
  
  <p>The XAML is trivial:</p>
  
  <pre><code>&lt;Window x:Class="ShowHide.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
      &lt;Grid&gt;
          &lt;Button
              Content="Test"
              HorizontalAlignment="Left"
              VerticalAlignment="Top"
              Click="Button_Click"/&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>If I go "up", it works as expected - <code>this</code> window gets hidden, the new one is created and is shown as a modal window. But when I close the currently visible window, all hidden windows "underneath" get shown at once and they're not modal anymore. Multiple lines appear in the output window.</p>
  
  <p>However, if I comment out the <code>Hide()</code> call, the problem doesn't seem to arise, i.e. I get to close modal windows one by one in reverse.</p>
  
  <p>To reproduce:</p>
  
  <ol>
  <li>Run the code.</li>
  <li>Press the "Test" button. The current window will hide and the new one will appear.</li>
  <li>Press the "Test" button in the new window. Another window will be created again. You can repeat this step as many times as you want.</li>
  <li>Close the window. Older windows will re-appear all at once and neither will be modal.</li>
  </ol>
  
  <p>Is this by design? What would your workaround be?</p>