XAML MenuBar

By Fons Sonnemans, 27-aug-2018

I'm in the process of learning the new Windows SDK Preview. Today's subject is the new MenuBar control. You can now create menus with submenus in your UWP apps. Before you could use the Menu control from the Windows Community Toolkit.


I have created a small demo page which displays the following menu.

The XAML contains the new MenuBar control which contains two MenuBarItem elements. Each MenuBarItem contains MenuFlyoutItem, MenuFlyoutSeparator or MenuFlyoutSubItem elements. 

<Page x:Class="MenuBarDemo.MainPage"
      Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <MenuBar VerticalAlignment="Top">
            <MenuBarItem Title="File"
                <MenuFlyoutItem Text="Open"
                        <KeyboardAccelerator Key="O"
                                             Modifiers="Control" />
                <MenuFlyoutSeparator />
                <MenuFlyoutItem Text="Save"
                                Command="{x:Bind SaveCommand}">
                        <KeyboardAccelerator Key="S"
                                             Modifiers="Control" />
                <MenuFlyoutSubItem Text="Demo">
                    <MenuFlyoutItem Text="A"
                                    Command="{x:Bind DemoCommand}"
                                    CommandParameter="{Binding Text, 
                                        RelativeSource={RelativeSource Self}, 
                                        Mode=OneTime}" />
                    <MenuFlyoutItem Text="B"
                                    Command="{x:Bind DemoCommand}"
                                    CommandParameter="{Binding Text, 
                                        RelativeSource={RelativeSource Self}, 
                                        Mode=OneTime}" />
                    <MenuFlyoutItem Text="C"
                                    Command="{x:Bind DemoCommand}"
                                    CommandParameter="{Binding Text, 
                                        RelativeSource={RelativeSource Self}, 
                                        Mode=OneTime}" />
            <MenuBarItem Title="Help"
                <MenuFlyoutItem Text="About"
                                Click="MenuFlyoutItemAbout_Click" />

The C# code with the Click handlers and the Commands looks like this.

public sealed partial class MainPage : Page {
    public ICommand SaveCommand { get; }
    public ICommand DemoCommand { get; }

    public MainPage() {
        this.SaveCommand = new RelayCommand(OnSave);
        this.DemoCommand = new RelayCommand<string>(OnDemo);

    private async void OnDemo(string text) {
        await new MessageDialog($"Demo {text}").ShowAsync();

    private async void OnSave() {
        await new MessageDialog("Save").ShowAsync();

    private async void MenuFlyoutOpen_Click(object sender, RoutedEventArgs e) {
        await new MessageDialog("Open").ShowAsync();

    private async void MenuFlyoutItemAbout_Click(object sender, RoutedEventArgs e) {
        await new MessageDialog("About").ShowAsync();

AccessKey and KeyboardAccelerators

The MenuBarItem have an AccessKey assigned. So if you press the Alt key on your keyboard you get the following output. Alt+F will open the File menu, Alt+H will open the Help menu.

The Open and Save MenuFlyoutItem have a KeyboardAccelerator. Ctrl+O will execute the Open menu, Ctrl+S will execute the Save menu.


The MenuBar is a great new addition. It will help me writing nice LOB applications. You can download this sample project from this GitHub repository.


Leave a Comment

Leave a Comment
5 + 5 =


  • Elsie Garth
    13 apr 2019 01:08
    Hi We are from Blogger Magazine, we have read your blog and we were very impressed, so we want to congratulate you because your blog has been nominated for Blogger Award 2019. The winners will be announced on 2 May. You can find more information about the award ceremony on this site. http://bit.ly/BloggerAward2019 greetings Blogger Magazine

All postings/content on this blog are provided "AS IS" with no warranties, and confer no rights. All entries in this blog are my opinion and don't necessarily reflect the opinion of my employer or sponsors. The content on this site is licensed under a Creative Commons Attribution By license.