liveBook · Manning

Menu item

As explained in .NET MAUI in Action

MenuItem is a .NET MAUI Shell element representing an actionable item in a flyout menu that invokes an action instead of navigating to a page.

A MenuItem adds an action to a .NET MAUI Shell flyout. Unlike a FlyoutItem, which takes the user to a page or group of pages, a MenuItem runs functionality that should be available across the app. A logout action is a typical use: it executes logout logic rather than navigates somewhere. section 7.5.1

Place MenuItem elements inside Shell after enabling the flyout with FlyoutBehavior="Flyout". Give each item visible text and, when helpful, an icon. Tapping or clicking the item can invoke either its Clicked event handler or its Command, letting the action live in code-behind or in a binding context. section 7.5.1 section 7.5.3

Choose the Shell element by what the flyout entry should do:

  • Use MenuItem for functionality such as logging out; it is not a route to an app page. section 7.5.1
  • Use FlyoutItem to expose a page or a group of pages. A FlyoutItem can contain multiple children. section 7.5.1
  • Use Shell sections and tabs to organize pages within navigable areas of the app. section 7.5.1

Menu items can share a consistent appearance through Shell.MenuItemTemplate. The template receives each item as its binding source, so a layout can bind an Image to Icon and a Label to Text. One template applies to every MenuItem in that Shell, making it useful when the flyout has several actions. section 7.5.3

Add a Logout action to a Shell flyout

Enable the flyout, then add a logout item before Shell closes: <Shell FlyoutBehavior="Flyout"> ... <MenuItem Text="Logout" IconImageSource="icon_logout.png" /> </Shell> At this stage it supplies the visible action. Wire Clicked or Command when the logout behavior is ready, and use Shell.MenuItemTemplate to refine the icon-and-label layout. section 7.5.3 section 7.5.1

Figure 7.13 The flyout menu in Shell consists of a customizable header and footer, flyout items for navigating the app, and menu items for executing code.

The flyout diagram places menu items alongside navigation items and its customizable header and footer, clarifying their distinct roles. section 7.5.1

How .NET MAUI in Action covers it

How deep it goes
Explains setup, Clicked or Command invocation, and shared item templating; it defers implementing the logout behavior.
Examples
Uses a Logout flyout item with an imported icon and an icon-and-text Shell.MenuItemTemplate.
What it assumes
Teaches flyout activation and MenuItem configuration from XAML while building on Shell, bindings, and data-template usage.
What you can do after
Apply it via .NET MAUI Shell to place and style a flyout action, then connect it to an event handler or command.
How it connects
Distinguishes MenuItem from FlyoutItem, Shell sections, tabs, Clicked events, commands, data templates, and binding.

Also explained in

Compare how 2 books explain menu item →

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.