How to keep a ContextMenu visible behind a modal dialog
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.
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.
ContextMenu.StaysOpen Property
精彩评论