title: How to prevent raise of LostFocus on MouseDown on an control
body: <p><strong>The question is pretty simple:</strong> How do I prevent <code>LostFocus</code> from getting raised on <code>MouseDown</code> on a control that already got focus?</p>
  
  <p>I have the following control (temporary test with all the event bindings):</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;Grid Name="gBase" Focusable="True" MouseUp="SetFocus" MouseDown="SetFocus" MouseMove="gBase_MouseMove" PreviewDragEnter="gBase_PreviewDragEnter" LostFocus="gBase_LostFocus" GotFocus="gBase_GotFocus"  Background="DarkRed" Width="500" Height="250" /&gt;
  </code></pre>
  
  <p>And the following code behind:</p>
  
  <pre class="lang-cs prettyprint-override"><code>private void SetFocus(object sender, MouseButtonEventArgs e)
  {
      Grid g = sender as Grid;            
      g.Focus();
  }
  
  private void gBase_LostFocus(object sender, RoutedEventArgs e)
  {
      Grid g = sender as Grid;
      g.Background = Brushes.DarkRed;
  
  }
  
  private void gBase_GotFocus(object sender, RoutedEventArgs e)
  {
      Grid g = sender as Grid;
      g.Background = Brushes.Aquamarine;
  }
  
  private void gBase_MouseMove(object sender, MouseEventArgs e)
  {
      if (e.LeftButton == MouseButtonState.Pressed)
      {
          Grid g = sender as Grid;
          g.Focus();
      }
  }
  
  private void gBase_PreviewDragEnter(object sender, DragEventArgs e)
  {
      Grid g = sender as Grid;
      g.Focus();
  }
  </code></pre>
  
  <p>The behaviour is almost of that I want to achieve, if I click on the Grid it get focus.</p>
  
  <p>The problem is that if the Grid already got focus it will lose it while I have the mouse button down and not regain it until I release or move. My prefered behaviour would be to prevent that it loses focus in the first place.</p>