title: Hiding popup on mouse click with Popup.StaysOpen in WPF
body: <p>I got my UserControl that contain:</p>
  
  <ul>
  <li>Button</li>
  <li>Popup (contain Text block)</li>
  </ul>
  
  <p>XAML</p>
  
  <pre><code>&lt;UserControl&gt;
  &lt;button Name="btnShowPopup" Content="Button" Click="Button_Click"/&gt;
  &lt;Popup Name="popup" StaysOpen="true"&gt;
  &lt;TextBlock Text="Popup"/&gt;
  &lt;/Popup&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>Code Behide</p>
  
  <pre><code>private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
  {
     this.popup.IsOpen=!this.popup.IsOpen;
  }
  </code></pre>
  
  <p>QUESTION: I want to hide the popup, when mouse click on anywhere outside the btnShowPopup button.</p>
  
  <p>NOTE: I tried change <code>StaysOpen="false"</code> and when <code>btnShowPopup.MouseDown</code> event:
  <code>this.popup.IsOpen=!this.popup.IsOpen;</code>
  But this solution cause another problem: when <code>btnShowPopup.MouseUp</code> event, the Popup is disappear.</p>
  
  <p>Please help.</p>