I have a button that when clicked opens a Popup. The Popup is a sub-menu containing more buttons. When one of the buttons on the sub-menu are clicked the Popup closes. I also want the Popup to close when the user clicks somewhere outside the Popup. It's also important to note that the majority of the screen is taken up by a WindowsFormsHost that displays an OpenGL Win Forms control.
Closing the Popup when a sub-menu button is clicked I've been able to do. Within the click handler for those buttons I close the Popup. However, closing the Popup when clicking somewhere else is where I've run into a problem.
Things I've tried:
Setting PopUp.StaysOpen to false. This works in that when clicking elsewhere on the screen, the Popup closes. However, on the Win Forms control it seems to require a click to close the Popup then a second click to perform what ever action. This is very undesirable.
I've tried handling the LostFocus event for the button that opens the Popup and setting StaysOpen to true. This works in that clicking off the Popup doesn't require the second click on the Win Forms control. The problem now is that the LostFocus event is handled and the Popup closed before it reads a click on any buttons on the Popup. This makes the sub-menu unusable.