Table of Contents

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

text string

The 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

Action

Bindings

Lazily-allocated binding collection. Disposed by MenuControl when the item is detached from the menu tree.

public BindingCollection Bindings { get; }

Property Value

BindingCollection

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

Rectangle

Children

Gets the observable list of child menu items (submenu). Mutations are reflected by the owning MenuControl automatically.

public MenuItemCollection Children { get; }

Property Value

MenuItemCollection

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

Color?

HasChildren

Gets whether this menu item has any children (is a submenu).

public bool HasChildren { get; }

Property Value

bool

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

bool

IsOpen

Gets or sets whether this menu item's dropdown/submenu is currently open. Managed internally by MenuControl.

public bool IsOpen { get; }

Property Value

bool

IsSeparator

Gets or sets whether this menu item is a separator (horizontal line).

public bool IsSeparator { get; set; }

Property Value

bool

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

MenuControl

Parent

Gets or sets the parent menu item. Null for top-level items.

public MenuItem? Parent { get; }

Property Value

MenuItem

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

string

Tag

Gets or sets user-defined data associated with this menu item.

public object? Tag { get; set; }

Property Value

object

Text

Gets or sets the display text for this menu item.

public string Text { get; set; }

Property Value

string

Methods

AddChild(MenuItem)

Adds a child menu item to this item's submenu.

public void AddChild(MenuItem item)

Parameters

item MenuItem

The 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

int

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?)

protected void OnPropertyChanged(string? propertyName = null)

Parameters

propertyName string

ToString()

Returns a string representation of this menu item for debugging.

public override string ToString()

Returns

string

Events

PropertyChanged

Occurs when a property value changes.

public event PropertyChangedEventHandler? PropertyChanged

Event Type

PropertyChangedEventHandler