🏗️
MauiReactor
  • What is MauiReactor?
  • What's new in Version 2
  • What's new in Version 3
  • Getting Started
  • Getting Started Version 2
  • Components
    • State-less Components
    • Stateful Components
      • Inline Components
    • Component life-cycle
    • Component Properties
    • Component with children
    • Component Parameters
    • Theming
    • Navigation
      • NavigationPage
      • Shell
      • Back button
    • Controls
      • Button
      • RadioButton
      • FlyoutPage
      • CollectionView
        • Interactions
        • Layout
        • Selection
        • Empty view
        • Scrolling
        • Grouping
      • IndicatorView
      • Picker
      • Shell
      • Label
    • Wrap 3rd party controls
      • Lottie animations
      • Provide DataTemplate to native controls
    • Accessing native controls
    • Animation
      • Property-Based
      • AnimationController
      • Timer
    • Graphics
      • CanvasView control
    • Window
    • Testing
    • XAML Integration
  • Deep dives
    • Native tree and Visual tree
    • Dependency injection
    • Working with the GraphicsView
    • Migrating from MVVM Model
    • Using XAML Resources
    • Behaviors
  • resources
    • Source and Sample Applications
  • Q&A
    • How to deal with state shared across Components?
    • Does this support ObservableCollection for CollectionView?
    • Do we need to add states to create simple animations such as ScaleTo, FadeTo, etc on tap?
    • How to deal with custom dialogs/popups?
  • How to create a Menu/ContextMenu?
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub

How to create a Menu/ContextMenu?

How to create a menu or a context menu in Maui desktop app.

.NET Maui allows developers to create Menus and ContextMenu for desktop apps.

In MauiReactor you can easily add a Menu bar to a desktop application by adding the MenuBarItem control under a page like it's shown in the following example:

new ContentPage
{
    new MenuBarItem("File")
    {
        new MenuFlyoutSubItem("Project")
        {
            new MenuFlyoutItem("Open...")
                .OnClicked(OnOpenProject),
        },
        new MenuFlyoutSeparator(),
        new MenuFlyoutItem("Exit")
            .OnClicked(OnExitApplication),
    },

    RenderBody()
}

For the context menu, you have to add the MenuFlyout under the control that should show the menu like it's shown below:

new Label(person.Initial)
{
    new MenuFlyout
    {
        new MenuFlyoutItem("MenuItem1")
            .OnClicked(()=>OnClickMenuItem("MenuItem1")),
        new MenuFlyoutItem("MenuItem2")
            .OnClicked(()=>OnClickMenuItem("MenuItem2")),
        new MenuFlyoutItem("MenuItem3")
            .OnClicked(()=>OnClickMenuItem("MenuItem3")),
    }
}

Please note that not all controls support the context menu (like the ViewCell): for a list of unsupported controls please refer to official .NET MAUI documentation.

PreviousHow to deal with custom dialogs/popups?

Last updated 3 months ago

Was this helpful?