How to close popups used as submenus in WPF

I have a button that when clicked opens a popup. A popup menu is a submenu containing more buttons. When you click one of the buttons in the submenu, the popup window closes. I also want the Popup to close when the user clicks somewhere outside of the Popup. It is also important to note that most of the screen is occupied by WindowsFormsHost, which displays the OpenGL Win Forms control.

Closes the popup when the submenu button is pressed. I could do it. Inside the click handler for these buttons, I close the popup. However, closing the popup when clicked elsewhere is where I ran into the problem.

Things I tried:

Configure PopUp.StaysOpen false. This works in that when you click elsewhere on the screen, the popup closes. However, the Win Forms control requires a click to close the pop-up window, and then a second click to complete all the actions. This is very undesirable.

I tried to handle the LostFocus event for the button that opens the popup and the StaysOpen parameter is true. This works in that when you click on Popup, you do not need a second click on the Win Forms control. Now the problem is that the LostFocus event is being processed, and the popup closes before it reads a click on any buttons on the popup. This makes it impossible to use the submenu.

+3
1

, WPF. WPF , WinForms Win32.

WinForms WPF, , , .

, WinForms WndProc Click IsOpen false .

, , .

+1

Source: https://habr.com/ru/post/1708441/


All Articles