Class MenuBarItem
A MenuItem-derived item for use in a MenuBar. Each MenuBarItem holds either a PopoverMenu (modal, default) or an inline SubMenu (non-modal) that is displayed as a drop-down menu when the item is selected. The behavior is controlled by the UsePopoverMenu property.
public class MenuBarItem : MenuItem, IDisposable, ISupportInitializeNotification, ISupportInitialize, IOrientation, IValue, IMenuBarEntry, IDesignable
- Inheritance
-
MenuBarItem
- Implements
- Inherited Members
- Extension Methods
Remarks
When UsePopoverMenu is true (default), MenuBarItem uses a PopoverMenu — a modal, overlay-rendered drop-down registered with the Application popover system.
When UsePopoverMenu is false, MenuBarItem uses the inherited SubMenu mechanism — a non-modal, inline drop-down rendered as a sibling view of the MenuBar. This mode is designed for scenarios that need non-modal menus — for example, the Terminal.Gui Designer (TGD).
PopoverMenu Integration: When PopoverMenu is set, the popover's
Target is set to this MenuBarItem (creating a CommandBridge
that bridges Activate commands from the popover back to this item), and the
popover's Anchor is set to position the drop-down below this MenuBarItem.
PopoverMenu Visibility: Use PopoverMenuOpen to get or set whether the PopoverMenu is visible. The PopoverMenuOpenChanged event fires when visibility changes, relayed from VisibleChanged.
Activation: Overrides OnActivating(CommandEventArgs) to toggle the menu open/closed. Bridged commands (originating from within the menu) are ignored to avoid unintended toggling. A custom HotKey handler skips SetFocus() before invoking Activate, preventing premature menu opening when switching between MenuBarItems via HotKey.
See Shortcut Deep Dive for details on the underlying command routing and BubbleDown pattern.
See Menus Deep Dive for the full menu system architecture, class hierarchy, command routing, and usage examples.
Constructors
- MenuBarItem()
Creates a new instance of MenuBarItem.
- MenuBarItem(string, IEnumerable<View>)
Creates a new instance of MenuBarItem with the
menuItemsautomatcialy added to a PopoverMenu. This is a helper for the most common MenuBar use-cases.
- MenuBarItem(string, PopoverMenu?)
Creates a new instance of MenuBarItem with the specified
popoverMenu. This is a helper for the most common MenuBar use-cases.
- MenuBarItem(View?, Command, string?, PopoverMenu?)
Creates a new instance of MenuBarItem. Each MenuBarItem typically has a PopoverMenu that is shown when the item is selected.
Properties
- PopoverMenu
The Popover Menu that will be displayed when this item is selected.
- PopoverMenuOpen
Gets or sets whether the PopoverMenu is open and visible or not. Delegates to PopoverMenu.Visible.
- 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).
- UsePopoverMenu
Gets whether this entry uses a modal PopoverMenu (true, default) or an inline SubMenu (false) for its dropdown. This property must be set at construction time and cannot be changed after initialization.
Methods
- Dispose(bool)
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
- EnableForDesign()
Causes the View to enable design-time mode. This typically means that the view will load demo data and be configured to allow for design-time manipulation.
- EndInit()
Signals the View that initialization is ending. See ISupportInitialize.
- OnActivating(CommandEventArgs)
Called when the user has performed an action (e.g. Activate) causing the View to change state or preparing it for interaction. Set CommandEventArgs.Handled to true and return true to indicate the event was handled and processing should stop.
- OnKeyDownNotHandled(Key)
Called when the user has pressed key it wasn't handled by KeyDown and was not bound to a key binding.
Events
- MenuOpenChanged
Raised when the menu open state has changed. In popover mode, this relays PopoverMenuOpenChanged. In inline mode, this relays SubMenu visibility changes.
- PopoverMenuOpenChanged
Raised when PopoverMenuOpen has changed. Relayed from VisibleChanged.