Home > DeveloperSection > Forums > How can I hide the popup, when mouse click on anywhere outside using wpf?
jacob rasel
jacob rasel

Total Post:88

Points:616
Posted on    August-19-2013 7:40 AM

 WPF WPF 
Ratings:


 1 Reply(s)
 6215  View(s)
Rate this:
Hi developers!

I got my UserControl that contain:

    Button

    Popup (contain Text block)

.XAML file 

<UserControl>

<button Name="btnShowPopup" Content="Button" Click=" btnShowPopup _Click"/>

<Popup Name="popup" StaysOpen="true">

<TextBlock Text="Popup"/>

</Popup>

</UserControl> 

Code Behide 

private void btnShowPopup _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.

please help me. thank in advance!



shreesh chandra shukla
shreesh chandra shukla

Total Post:105

Points:735
Posted on    August-19-2013 8:09 AM

Hi!

You can use to ToggleButton instead of button it would easy.

<ToggleButton x:Name="myToggleButton" />

<Popup x:Name="Popup"

    IsOpen="{Binding Path=IsChecked, ElementName= myToggleButton }"

    Placement="Right"

    PlacementTarget="{Binding ElementName= myToggleButton }"

    AllowsTransparency="True"

    Focusable="False"

    PopupAnimation="Fade"

    StaysOpen="False">

    <Textblock Text="Write Here content" />

</Popup>


Don't want to miss updates? Please click the below button!

Follow MindStick