Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to place close [x] in WPF popup

Tags:

c#

wpf

popup

I have succeed creating a popup using this code in c# and wpf

<Popup Name="myPopup" IsOpen="True">
<Label Name="myLabel" Content="This is a popup!" Background="AliceBlue" Foreground="Blue"/>
        </Popup> 

I use the code below to hide it when one mouse-click outside it and it works right.

myPopup.IsOpen = true;
myPopup.Placement = System.Windows.Controls.Primitives.PlacementMode.Mouse;
myPopup.StaysOpen = false;
myPopup.Height = 500;
myPopup.Width = 500;
myPopup.IsOpen = true;

My problem is that I would like to add a close button(or something like [x]). It will hide when this is clicked, just like dialog in windows forms. Any ideas?Thanks in advance

like image 957
Cheruiyot Felix Avatar asked Nov 29 '25 00:11

Cheruiyot Felix


1 Answers

In one of our apps we had a similar requirement and we solved it by binding IsOpen to a property of the view model. When you add a button use the Click event handler to set the property to false which will close the popup.

like image 153
ChrisWue Avatar answered Nov 30 '25 14:11

ChrisWue



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!