liveBook · Manning

Menu bar items collection

As explained in .NET MAUI in Action

MenuBarItems is a .NET MAUI application property containing MenuBarItem objects that define a desktop menu.

The MenuBarItems collection is a .NET MAUI page property containing MenuBarItem objects. It adds desktop menus that follow the host operating system’s conventions: Windows places the menu at the top of the window, while macOS places it at the top of the screen. iOS and Android do not render the collection. section 7.2.5 section 10.3.3

Use the collection when a desktop application has features that are easier to organize in menus than in on-screen buttons:

  • Add a top-level MenuBarItem such as Help. section 10.3.3
  • Place MenuFlyoutItem entries inside it for labeled actions, or group entries with MenuFlyoutSubItems. section 10.3.3
  • Execute an action through a MenuFlyoutItem Clicked event or Command binding. section 10.3.3
  • Do not add OnIdiom logic merely to hide the menu on mobile; the menu bar is desktop-only. section 10.3.3
Listing 10.20 The ReportPage.xaml menu
<ContentPage.MenuBarItems>                  #1
    <MenuBarItem Text="Help">               #2
        <MenuFlyoutItem Text="About"        #3
 
                        Command="{Binding
 ShowAboutPageCommand}"/>                 #4
    </MenuBarItem>
</ContentPage.MenuBarItems>

A compact XAML example shows the collection, a Help menu, an About item, and a command binding. section 10.3.3

How .NET MAUI in Action covers it

How deep it goes
Explains platform rendering, menu composition, and action wiring, but defers mobile menu rendering because those platforms omit the collection.
Examples
Demonstrates a ReportPage Help menu containing an About MenuFlyoutItem bound to ShowAboutPageCommand.
What you can do after
Apply it via .NET MAUI XAML to configure desktop menus and connect menu selections to commands or event handlers.
How it connects
Connects MenuBarItem with MenuFlyoutItem, MenuFlyoutSubItems, command binding, and desktop application layouts.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of .NET MAUI in Action. The section links point to the parts of the book it draws on.