Problem with Popup.StaysOpen in WPF

Posted by Tola Ch. on Stack Overflow See other posts from Stack Overflow or by Tola Ch.
Published on 2010-02-22T01:45:42Z Indexed on 2010/06/11 11:42 UTC
Read the original article Hit count: 646

Filed under:
|

I got my UserControl that contain:

  • Button
  • Popup (contain Text block)

XAML <UserControl> <button Name="btnShowPopup" Content="Button" Click="Button_Click"/> <Popup Name="popup" StaysOpen="true"> <TextBlock Text="Popup"/> </Popup> </UserControl>

Code Behide

private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
   this.popup.IsOpen=!this.popup.IsOpen;
}

QUESTION: I want to hide the popup, when mouse click on anywhere outside the btnShowPopup button.

NOTE: I tried change StaysOpen="false" and when btnShowPopup.MouseDown event: this.popup.IsOpen=!this.popup.IsOpen; But this solution cause another problem: when btnShowPopup.MouseUp event, the Popup is disappear.

Please help.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about popup