MenuBar
The MenuBar widget provides a traditional menu bar interface with dropdown menus, similar to desktop applications.
Overview
Section titled “Overview”MenuBar displays a horizontal bar of menu items. Each item can have a submenu that appears as a dropdown when activated.
Properties
Section titled “Properties”Items (IReadOnlyList<MenuItem>)
Section titled “Items (IReadOnlyList<MenuItem>)”The menu items in the menu bar.
foreach (var item in menuBar.Items){ Console.WriteLine(item.Text);}Color Properties
Section titled “Color Properties”SelectedBackgroundColor: Background for selected menu itemSelectedForegroundColor: Text color for selected menu itemDropdownBackgroundColor: Background for dropdown menusDropdownForegroundColor: Text color for dropdown itemsDropdownSelectedBackgroundColor: Background for selected dropdown itemDropdownDisabledForegroundColor: Text color for disabled itemsDropdownBorderColor: Border color for dropdowns
Methods
Section titled “Methods”AddItem(MenuItem item)
Section titled “AddItem(MenuItem item)”Adds a menu item to the menu bar.
var item = new MenuItem("File");menuBar.AddItem(item);AddMenu(string text, params MenuItem[] subItems)
Section titled “AddMenu(string text, params MenuItem[] subItems)”Creates and adds a menu with submenu items.
menuBar.AddMenu("File", new MenuItem("New", () => CreateNew(), 'N'), new MenuItem("Open", () => OpenFile(), 'O'), MenuItem.Separator(), new MenuItem("Exit", () => app.Stop(), 'x'));Events
Section titled “Events”ItemSelected
Section titled “ItemSelected”Raised when a menu item is selected.
menuBar.ItemSelected += (item) =>{ Console.WriteLine($"Selected: {item.Text}");};Keyboard Navigation
Section titled “Keyboard Navigation”- Left/Right Arrow: Navigate menu items
- Enter/Space/Down Arrow: Open dropdown menu
- Up/Down Arrow (in dropdown): Navigate submenu items
- Enter/Space: Select menu item
- Escape: Close dropdown
- Tab: Navigate to next focusable widget
Usage Example
Section titled “Usage Example”var menuBar = new MenuBar{ X = 0, Y = 0, Width = 80, Height = 1, ForegroundColor = Color.Black, BackgroundColor = ColorHelper.FromRgb(200, 200, 200)};
menuBar.AddMenu("File", new MenuItem("New", () => Console.WriteLine("New"), 'N'), new MenuItem("Open", () => Console.WriteLine("Open"), 'O'), MenuItem.Separator(), new MenuItem("Exit", () => app.Stop(), 'x'));
menuBar.AddMenu("Edit", new MenuItem("Cut", () => Console.WriteLine("Cut"), 't'), new MenuItem("Copy", () => Console.WriteLine("Copy"), 'C'), new MenuItem("Paste", () => Console.WriteLine("Paste"), 'P'));Related Widgets
Section titled “Related Widgets”- MenuItem - Individual menu items
- MenuDropdown - Dropdown menu (internal)