title: ALT-TAB always activates main window in WPF app with multiple owned windows
body: <p>On Windows 7, .NET 4.0 I have a problem that can be reproduced by copying the following code into a blank WPF application generated by Visual Studio:</p>
  
  <pre><code>    public MainWindow()
      {
          InitializeComponent();
          Loaded += new RoutedEventHandler(MainWindow_Loaded);
      }
  
      void MainWindow_Loaded(object sender, RoutedEventArgs e)
      {
          new Window() { Title = "Test", ShowInTaskbar = false, Owner = this }.Show();
      }
  </code></pre>
  
  <ol>
  <li>Run app</li>
  <li>Activate secondary window</li>
  <li>Alt-Tab to other running application</li>
  <li>Use mouse to activate our WPF app in taskbar</li>
  </ol>
  
  <p>Now the WPF app is active again, with the secondary window activated and the main window deactivated, which is the expected (and desired) behavior.</p>
  
  <p>Now do this instead (only step 4 differs):</p>
  
  <ol>
  <li>Run app</li>
  <li>Activate secondary window</li>
  <li>Alt-Tab to other running application</li>
  <li>Alt-Tab back to our WPF app</li>
  </ol>
  
  <p>The WPF app is active again, but now the main window is activated.
  Adding this code</p>
  
  <pre><code>private void Application_Activated(object sender, EventArgs e)
  {
      Windows[1].Activate();
  }
  </code></pre>
  
  <p>to App.xaml.cs does not solve the problem because now in the second case both windows are activated. Also, clicking the secondary window does not deactivate the main window. I have to click the (already activated) main window and the secondary window again to achieve this.</p>
  
  <p>How can I avoid this (only the secondary window should be active in both cases)?</p>