Skip to content

TextMenu

Iuga Alexandru edited this page Sep 2, 2018 · 7 revisions

Description

Displays a list of items and asks the user to select one by typing its id. When an item is selected, if it has an associated command, it is executed.

Features

  • Id selection - Select a menu item by typing its id.
  • Enable/Disable menu items - The disabled items are displayed with another color and cannot be selected.
  • Show/Hide menu items - The hidden items are not displayed at all.
  • Commands - Can attach Commands to menu items that will be executed when the menu item is selected.
  • IRepeatableSupport - This control offers support to be used by the ControlRepeater.

Example

Please see also the demo application.

private void DisplayMenu()
{
    TextMenu textMenu = new TextMenu
    {
        Title = new TextBlock
        {
            Text = "Demo Application",
            ForegroundColor = ConsoleColor.Cyan,
            MarginBottom = 1
        },
        MarginTop = 1,
        MarginBottom = 1,
        EraseAfterClose = true,
    };

    textMenu.AddItems(new List<TextMenuItem>
    {
        new TextMenuItem
        {
            Id = "1",
            Text = "New Game",
            Command = new NewGameCommand()
        },
        new TextMenuItem
        {
            Id = "2",
            Text = "Save Game",
            Command = new SaveGameCommand()
        },
        new TextMenuItem
        {
            Id = "3",
            Text = "Load Game",
            Command = new LoadGameCommand()
        }
    },
    ...
);

    textMenu.Display();
}

Result:

Clone this wiki locally