I make a very simple window:
var wndPpList = new Window()
{
SizeToContent = SizeToContent.WidthAndHeight,
WindowStyle = WindowStyle.None,
ShowInTaskbar = false,
BorderBrush = GetColour_Cyan(),
BorderThickness = new Thickness(3),
};
now I want to make that when I click outside it, it closes.
I have seen a lot of posts where in order to achieve this, they activate the mouse
wndPpList.CaptureMouse();
wndPpList.Deactivated += (sender, args) =>
{
wndPpList.ReleaseMouseCapture();
wndPpList.Close();
};
but the event Deactivated is just not fired.
Thanks for any help
Patrick
Using the MouseDown event you can check if the event was raised outside of the popup. Then you can close the popup window.
if you need to fire the event more then one time you need to register and unregister it properly. This is an example with a button to open the popup. However if you open two popup windows at the same time you will get propblems. So you should disable the button while the popup is shown or use some other machanism to only show one popup.