Class MenuItem
- Namespace
- SharpConsoleUI.Controls
- Assembly
- SharpConsoleUI.dll
Represents a menu item with support for hierarchical menu structures. Implements INotifyPropertyChanged so display properties can be data-bound from a view model via BindingExtensions.
public class MenuItem : INotifyPropertyChanged
- Inheritance
-
MenuItem
- Implements
- Inherited Members
- Extension Methods
Constructors
MenuItem()
Creates a MenuItem whose Children collection is owned by this item.
public MenuItem()
MenuItem(string)
Creates a MenuItem with the specified display text.
public MenuItem(string text)
Parameters
textstringThe display text for this menu item.
Properties
Action
Gets or sets the action to execute when this menu item is selected. Not called for items with children (submenus).
public Action? Action { get; set; }
Property Value
Bindings
Lazily-allocated binding collection. Disposed by MenuControl when the item is detached from the menu tree.
public BindingCollection Bindings { get; }
Property Value
Bounds
Gets or sets the screen-space bounds of this menu item for hit testing. Managed internally by MenuControl.
public Rectangle Bounds { get; }
Property Value
Children
Gets the observable list of child menu items (submenu). Mutations are reflected by the owning MenuControl automatically.
public MenuItemCollection Children { get; }
Property Value
ForegroundColor
Gets or sets the custom foreground color for this menu item. If set, this color will be used instead of the default menu colors (unless item is disabled or highlighted).
public Color? ForegroundColor { get; set; }
Property Value
HasChildren
Gets whether this menu item has any children (is a submenu).
public bool HasChildren { get; }
Property Value
IsEnabled
Gets or sets whether this menu item is enabled. Disabled items are shown but cannot be selected.
public bool IsEnabled { get; set; }
Property Value
IsOpen
Gets or sets whether this menu item's dropdown/submenu is currently open. Managed internally by MenuControl.
public bool IsOpen { get; }
Property Value
IsSeparator
Gets or sets whether this menu item is a separator (horizontal line).
public bool IsSeparator { get; set; }
Property Value
Owner
The MenuControl that owns this item (set when the item is attached to a menu tree). Null for items not currently in any menu.
public MenuControl? Owner { get; }
Property Value
Parent
Gets or sets the parent menu item. Null for top-level items.
public MenuItem? Parent { get; }
Property Value
Shortcut
Gets or sets the keyboard shortcut text displayed on the right (display only, not handled by MenuControl). Example: "Ctrl+S", "Alt+F4"
public string? Shortcut { get; set; }
Property Value
Tag
Gets or sets user-defined data associated with this menu item.
public object? Tag { get; set; }
Property Value
Text
Gets or sets the display text for this menu item.
public string Text { get; set; }
Property Value
Methods
AddChild(MenuItem)
Adds a child menu item to this item's submenu.
public void AddChild(MenuItem item)
Parameters
itemMenuItemThe menu item to add as a child.
GetDepth()
Gets the depth level of this menu item in the hierarchy (0 for top-level).
public int GetDepth()
Returns
GetPath()
Gets the full hierarchical path of this menu item. Example: "File/Recent/Document1.txt"
public string GetPath()
Returns
- string
A forward-slash separated path string.
OnPropertyChanged(string?)
Raises PropertyChanged.
protected void OnPropertyChanged(string? propertyName = null)
Parameters
propertyNamestring
ToString()
Returns a string representation of this menu item for debugging.
public override string ToString()
Returns
Events
PropertyChanged
Occurs when a property value changes.
public event PropertyChangedEventHandler? PropertyChanged