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
