In This Article

Overview

The BarMainMenu control is meant to be a replacement for a native Menu control. Its main benefit over a native Menu control is that it can be fully configured via MVVM.

Usage Scenarios

Window Main Menu

The BarMainMenu control usually appears at the top of a Window

Screenshot

A main menu at the top with one of its menus open

A main menu can be defined like this in XAML:

xmlns:actipro="http://schemas.actiprosoftware.com/avaloniaui"
...
<actipro:BarMainMenu>
	<actipro:BarMenuItem Label="File">
		<actipro:BarMenuItem Label="New" SmallImageSource="/Images/Icons/New16.png" Command="{Binding NewCommand}" InputGesture="Ctrl+N" />
		<actipro:BarMenuItem Label="Open" SmallImageSource="/Images/Icons/Open16.png" Command="{Binding OpenCommand}" InputGesture="Ctrl+O" />
		<actipro:BarMenuItem Label="Save" SmallImageSource="/Images/Icons/Save16.png" Command="{Binding SaveCommand}" InputGesture="Ctrl+S" />
		<actipro:BarMenuSeparator />
		<actipro:BarMenuItem Label="Exit" Command="{Binding ExitCommand}" />
	</actipro:BarMenuItem>
	<actipro:BarMenuItem Label="Edit">
		...
	</actipro:BarMenuItem>
	<actipro:BarMenuItem Label="View">
		...
	</actipro:BarMenuItem>
	<actipro:BarMenuItem Label="Help">
		...
	</actipro:BarMenuItem>
</actipro:BarMainMenu>

Child Controls

The BarMainMenu control expects BarMenuItem controls as its direct children.

Those BarMenuItem children can themselves host all Bars controls that are meant for a menu context. A powerful feature is the ability to use a popup menu item or split menu item to show a graphically-rich menu gallery in its popup menu.

Key Tips

Key tips in child controls are supported since BarMainMenu is a root key tip scope. Pressing keys like Alt will activate key tip mode the same as with a ribbon.

See the Key Tips topic for more information on key tips.

Screen Tips

The child controls of root menu items support screen tips, which are formatted tool tips. Screen tips attempt to display to the far side of the menu item.

See the Screen Tips topic for more information on screen tips.

MVVM Support

The optional companion MVVM Library defines a BarMainMenuViewModel class that is intended to be used as a view model for a BarMainMenu control.

If a BarMainMenuViewModel instance is bound to the BarMainMenu.DataContext, a built-in ControlTheme with resource key BarMainMenuControlTheme can be applied to configure bindings for all the view model's properties:

xmlns:actipro="http://schemas.actiprosoftware.com/avaloniaui"
...
<actipro:BarMainMenu ...
	DataContext="{Binding MainMenu}"
	Theme="{StaticResource {x:Static actipro:BarsMvvmResourceKeys.BarMainMenuControlTheme}}"
	/>
Tip

See the MVVM Support topic for more information on how to use the library's view models and view templates to create and manage your application's bars controls with MVVM techniques.