views:

47

answers:

2

I'm working on a WPF application which has a dropdown button. When "expanded", it displays a custom UserControl inside a ContextMenu. This control includes two buttons, one for Open and one for Save. The idea is for each of these buttons to display the appropriate file dialog.

My problem is that, when the dialog is displayed, the ContextMenu (and thus the control) closes. I'd like to keep it visible while the dialog is open. At the same time, I'd like the dialog to remain in front of/over it.

So my question is, can this be done at all in WPF? I suspect it has to do with how the parent Window handles the LostFocus event, but I'm not sure.

A: 

ContextMenu.StaysOpen Property

Wallstreet Programmer
According to the documentation, setting StaysOpen to true means "the menu should stay open until the IsOpen property changes to false". When the ContextMenu loses focus, its IsOpen property does change to false. Still, I'd overlooked the StaysOpen property, so thanks for pointing that out.
visual-kinetic
Looks like the property don't have any effect, see http://social.msdn.microsoft.com/forums/en-US/wpf/thread/3ce930bd-fc4e-493b-b5ff-2ebf16882e7a. You are better off using something else than a ContextMenu that you can control its visibility.
Wallstreet Programmer
A: 

Well, after working directly with the Popup class in a quick prototype app, I couldn't find any way to get the behavior I wanted. Either the Popup disappears when the modal dialog is displayed (StaysOpen == false), or it stays visible on top of the dialog (StaysOpen == true).

However, I did find a work-around that approximates the behavior I wanted: simply re-open the Popup (IsOpen = true) after the dialog is closed.

visual-kinetic