14

Is it possible to make a WPF menu item that, when clicked, does not close the dropdown menu?

Imagine a Preferences menu, with several checkbox-style preference settings as menu items. I want the ability to toggle several of them before closing the menu.

CLARIFICATION: This is only for some menu items, in some menus. File > Open should still close the menu, just like the user expects. Even the menu that has "non-closing" items will likely have "closing" items as well. I'm looking for per-item granularity.

Joe White
  • 94,807
  • 60
  • 220
  • 330

2 Answers2

44

MenuItem has a Property called StaysOpenOnClick which seems to be what you're looking for

So, to stop MenuItem from closing Menu/ContextMenu on click

<MenuItem Header="MenuItem That Doesn't Close On Click"
          StaysOpenOnClick="True"
          .../>
Fredrik Hedblad
  • 83,499
  • 23
  • 264
  • 266
1

Would the Popup visual be of any use here? You can show it at any position above your window. IIRC you must tell the popup to close yourself, so you can define when the popup is closed.

Using proper layout you can make it look like a menu or dropdown thing.

Thorsten Dittmar
  • 55,956
  • 8
  • 91
  • 139
  • I only want some of the menu items to be "non-closing" items. Other menu items would still close the menu, as would items in the other menus (File, Edit, etc.) – Joe White Mar 10 '11 at 14:03
  • Ah, I see. Then I got it wrong. I thought you were talking about a toplevel menu item. – Thorsten Dittmar Mar 10 '11 at 14:07