Problem with Popup.StaysOpen in WPF
- by Tola Ch.
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.