tags:

views:

886

answers:

1

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.

+1  A: 

There is probably some issue going on with WPF's focus system. WPF has it's own focus system that is completely separate from WinForms and standard Win32 windows.

When switching focus between WinForms and WPF, I bet there are some events that aren't firing properly.

A suggested fix would be to override your WinForms window's WndProc or Click event and manually set IsOpen to false on your popup.

I would expect this is the only thing that will fix it.

Jonathan.Peppers