A menu will usually contain a set of nested MenuItems. The first level of MenuItems represent the items that will be displayed horizontally along the menu. The second level of MenuItems represent the menu items that will be dropped down from the top-level and subsequent nested MenuItems represent sub-menus.
The text of the MenuItem is displayed by the Header property; the inner content of the MenuItem is where the sub-items are placed.
Separators are added by including a Separator control or a MenuItem with a header of "-".
Accelerator Keys
An accelerator key is a key on your keyboard that you can press to quickly access a menu. It is also sometimes called a hot key, access key or mnemonic.
If you will press Alt with the example above you will see that some letters are underlined. You can use a combination of Alt + underlined letter to navigate within a menu. In Avalonia to identify the accelerator key, you will need to use _ next character to this character would be an accelerator key.
Menu Commands
Like Button, commands can be bound to MenuItems. The command will be executed when the menu item is clicked or selected with the keyboard:
Menus can also be dynamically created using bindings and DataTemplate s. To do this, you will usually create a view model to represent your Window with a set of commands relating to the menu commands:
Next, you can create your menu structure using the view models. The following code when placed in a Window constructor will create a basic menu structure and assign it to the Window's DataContext.