---
title: "How can I hide the popup, when mouse click on anywhere outside using wpf?"  
description: "How can I hide the popup, when mouse click on anywhere outside using wpf?"  
author: "Anonymous User"  
published: 2013-08-19  
updated: 2013-08-19  
canonical: https://www.mindstick.com/forum/1415/how-can-i-hide-the-popup-when-mouse-click-on-anywhere-outside-using-wpf  
category: "wpf"  
tags: ["wpf"]  
reading_time: 1 minute  

---

# How can I hide the popup, when mouse click on anywhere outside using wpf?

Hi [developers](https://www.mindstick.com/articles/12875/blunders-you-must-avoid-while-hiring-java-developers-to-get-the-best-fulfilling-your-needs)!

I got my [UserControl](https://www.mindstick.com/forum/12739/set-the-enabled-property-of-a-usercontrol-from-codebehind) that contain:

[Button](https://www.mindstick.com/articles/63/how-to-add-button-in-datagridview-in-csharp-dot-net)

[Popup](https://www.mindstick.com/blog/11734/how-to-create-advanced-popup-or-banners-with-news-images-discounts-in-magento2) (contain Text [block](https://www.mindstick.com/forum/157599/explain-the-process-control-block-pcb-in-the-operating-system))

## .XAML file

<UserControl>

<button Name="btnShowPopup" [Content](https://www.mindstick.com/articles/13019/get-the-best-content-marketing-pricing-packages-for-your-brand)="Button" [Click](https://www.mindstick.com/articles/12423/social-login-magento-2-one-click-to-register-social)=" btnShowPopup _Click"/>

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

<TextBlock Text="Popup"/>

</Popup>

</UserControl>

## Code Behide

[private](https://www.mindstick.com/blog/11097/java-access-modifiers-the-public-and-the-private-modifiers) void btnShowPopup _Click(object sender, System.Windows.RoutedEventArgs e)

{

this.popup.IsOpen=!this.popup.IsOpen;

}

[QUESTION](https://www.mindstick.com/blog/23175/how-to-solve-neet-question-paper-in-less-time): I want to hide the popup, when mouse click on anywhere outside the btnShowPopup button.

please help me. thank in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!

## Replies

### Reply by shreesh chandra shukla

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>
```


---

Original Source: https://www.mindstick.com/forum/1415/how-can-i-hide-the-popup-when-mouse-click-on-anywhere-outside-using-wpf

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
