title: WPF Grid detect click outside
body: <p>I want to detect when the user has clicked outside the custom Grid, but when a user clicks on the grid, I allways receive the LostFocus event. Focusable is true, but it seems that the grid never gets focus. Can somebody please help me?</p>
  
  <pre><code>public class GridEditor : Grid
  {
      public GridEditor()
      {
          Loaded += GridEditor_Loaded;
      }
  
      private void GridEditor_Loaded(object sender, RoutedEventArgs e)
      {
          Focusable = true;
  
          this.LostFocus += new RoutedEventHandler(GridEditor_LostFocus);
      }
  
      void GridEditor_LostFocus(object sender, RoutedEventArgs e)
      {
          if (!this.IsKeyboardFocusWithin &amp;&amp; !this.IsMouseOver)
          {
              Commands.EditConfirmed.Execute(DataContext, this);
          }
      }
  </code></pre>