Class MenuItem
A Shortcut-derived item for use in a Menu. Displays a command, help text, and key binding and supports nested SubMenus for cascading menu hierarchies.
public class MenuItem : Shortcut, IDisposable, ISupportInitializeNotification, ISupportInitialize, IOrientation, IDesignable, IValue
- Inheritance
-
MenuItem
- Implements
- Derived
- Inherited Members
- Extension Methods
Remarks
MenuItem extends Shortcut to add support for hierarchical menus. Like Shortcut, it displays a CommandView (command text), HelpView (help text), and KeyView (key binding). When the user activates a MenuItem, the associated Action is invoked.
SubMenu Support: Set the SubMenu property to a Menu to create
cascading (nested) menus. When a SubMenu is set, a right-arrow glyph is displayed in the
KeyView and a CommandBridge connects the SubMenu back to this
MenuItem, bridging Activate and Accept
commands across the non-containment boundary.
Command Binding: A MenuItem can be bound to a Command on a TargetView. The key that TargetView has bound to the command will be used as the Key.
Mouse Behavior: When the mouse enters a MenuItem, it automatically receives focus, enabling hover-to-select behavior within menus.
MenuItem implements IValue, exposing Title as its value.
See Shortcut Deep Dive for details on command routing, the BubbleDown pattern, and how Shortcut coordinates commands between itself and its CommandView.
See Menus Deep Dive for the full menu system architecture, class hierarchy, command routing, and usage examples.
Constructors
- MenuItem()
Creates a new instance of MenuItem.
- MenuItem(View?, Command, string?, string?, Menu?)
Creates a new instance of MenuItem, binding it to
targetViewandcommand. The KeytargetViewhas bound tocommandwill be used as Key.
Properties
- SubMenu
The submenu to display when the user selects this menu item.
- SubMenuGlyph
Gets the glyph displayed in KeyView when a SubMenu is set. The default is RightArrow (►). Override to change the indicator (e.g., DownArrow for a drop-down menu bar entry).
Methods
- Dispose(bool)
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
- GetValue()
Gets the value as a boxed object.
- OnMouseEnter(CancelEventArgs)
Called when the mouse moves over the View's Frame and no other non-SubView occludes it. MouseLeave will be raised when the mouse is no longer over the Frame.