title: Weird KeyUp behaviour (main form handles events from child?!)
body: <p>The problem:</p>
  
  <ol>
  <li>KeyUp is handled by the grid in main window (<code>Grid_KeyUp</code>)</li>
  <li>Main window shows a child window (e.g. <code>MessageBox.Show(...)</code>)</li>
  <li>User presses [Return] (<code>Keys.Return</code>) to close the <code>MessageBox</code></li>
  <li>Main window actually GETS the KeyUp event from that keypress in MessageBox</li>
  </ol>
  
  <p>I have a very simple isolated sample that shows the problem I am having. Just create an empty WPF project and use this XAML:</p>
  
  <pre><code>&lt;Grid KeyUp="Grid_KeyUp"&gt;
      &lt;Button Click="Button_Click"&gt;&lt;/Button&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>And the code-behind:</p>
  
  <pre><code>public partial class MainWindow : Window
  {
      public MainWindow()
      {
          InitializeComponent();
      }
  
      private void Grid_KeyUp(object sender, KeyEventArgs e)
      {
          Console.WriteLine("KEYUP: " + e.Key);
      }
  
      private void Button_Click(object sender, RoutedEventArgs e)
      {
          MessageBox.Show(this, "TEST");
      }
  }
  </code></pre>
  
  <p>If you click the button and press [Return] to close the MessageBox the output window will print:</p>
  
  <pre><code>KEYUP: Return
  </code></pre>
  
  <p>Weird facts:</p>
  
  <ol>
  <li>I get the same behaviour when pressing [Escape] (<code>KEYUP: Escape</code> gets printed), but when I press [Space] the console does not print out anything!</li>
  <li>e.Source and e.OriginalSource point to the button in the main window (which is, obviously, wrong).</li>
  <li>If you put a breakpoint right after <code>MessageBox.Show(...)</code> the event does not get handled by out KeyUp handler (i.e. the output is empty).</li>
  </ol>
  
  <p>Could anyone explain to me what is happening?</p>
  
  <p>PS Target framework is: .NET 4 Client</p>