-
Notifications
You must be signed in to change notification settings - Fork 0
Concept Switching Menus
David Yates edited this page Jul 31, 2020
·
3 revisions
To switch menus, do the following
- Inject an IConsoleMenuController into the constructor of your class.
- In the WorkAsync method, call one of the three overloads of the IConsoleMenuController.DisplayMenuAsync method.
Example:
using System.Threading.Tasks;
using ConsoleMenuHelper;
namespace Example1
{
[ConsoleMenuItem("Hello1")]
public class LaunchSubMenuItem : IConsoleMenuItem
{
private readonly IConsoleMenuController _menuController;
public LaunchSubMenuItem(IConsoleMenuController menuController)
{
_menuController = menuController;
}
public async Task<ConsoleMenuItemResponse> WorkAsync()
{
await _menuController.DisplayMenuAsync("Hello2", "Hello Two", BreadCrumbType.Concatenate);
return await Task.FromResult(new ConsoleMenuItemResponse(false, true));
}
public string ItemText => "Show Hello 2 menu!";
/// <summary>Optional data from the attribute.</summary>
public string AttributeData { get; set; }
}
}
Notes
- Here I'm using the overload with the most parameters.
- I specify the name of the menu, "Hello2", which should be the title of the menu in the ConsoleMenuItemAttribute that decorates all your menu item classes.
- I specify a title, "Hello Two", for the menu. This will appear at the top of the menu above the options.
- I specify a breadcrumb trail type, BreadCrumbType.Concatenate. There are three different values available:
- BreadCrumbType.None - Don't show a breadcrumb trail
- BreadCrumbType.ParentOnly - Show the parent and child only
- BreadCrumbType.Concatenate - Look at the parents breadcrumb trail and add to it. If the parent doesn't have a breadcrumb trail then just use the parent's title to build one.