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
and immediately above any Dockable Toolbars host that is present.
A main menu at the top with one of its menus open
A main menu can be defined like this in XAML:
xmlns:bars="http://schemas.actiprosoftware.com/winfx/xaml/bars"
...
<bars:BarMainMenu>
<bars:BarMenuItem Label="File">
<bars:BarMenuItem Label="New" SmallImageSource="/Images/Icons/New16.png" Command="{Binding NewCommand}" InputGestureText="Ctrl+N" />
<bars:BarMenuItem Label="Open" SmallImageSource="/Images/Icons/Open16.png" Command="{Binding OpenCommand}" InputGestureText="Ctrl+O" />
<bars:BarMenuItem Label="Save" SmallImageSource="/Images/Icons/Save16.png" Command="{Binding SaveCommand}" InputGestureText="Ctrl+S" />
<bars:BarMenuSeparator />
<bars:BarMenuItem Label="Exit" Command="{Binding ExitCommand}" />
</bars:BarMenuItem>
<bars:BarMenuItem Label="Edit">
...
</bars:BarMenuItem>
<bars:BarMenuItem Label="View">
...
</bars:BarMenuItem>
<bars:BarMenuItem Label="Help">
...
</bars:BarMenuItem>
</bars: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 are not supported within a main menu.
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 Style
with resource key BarsMvvmResourceKeys.BarMainMenuStyle can be applied to configure bindings for all the view model's properties:
xmlns:bars="http://schemas.actiprosoftware.com/winfx/xaml/bars"
xmlns:themes="http://schemas.actiprosoftware.com/winfx/xaml/themes"
...
<bars:BarMainMenu ...
DataContext="{Binding MainMenu}"
Style="{StaticResource {x:Static themes:BarsMvvmResourceKeys.BarMainMenuStyle}}"
/>
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.