Bob Gatto

Bob Gatto

  • 1.6k
  • 44
  • 6.8k

How do I give functionallity to a MenuBarItem in a .NET maui app?

Apr 18 2023 3:51 PM

In my .NET maui app I created a menu like this:

<MenuBarItem Text="Passwords">
            <MenuFlyoutItem Text="New"/>
            <MenuFlyoutItem Text="Edit"/>
            <MenuFlyoutItem Text="Delete"/>
            <MenuFlyoutItem Text="Move"/>
        </MenuBarItem>
        <MenuBarItem Text="Groups">
            <MenuFlyoutItem Text="New"/>
            <MenuFlyoutItem Text="Delete"/>
            <MenuFlyoutItem Text="Rename"/>
        </MenuBarItem>
        <MenuBarItem Text="Tools">
            <MenuFlyoutSubItem Text="Password Viewing">
                <MenuFlyoutItem Text="Create Password"/>
                <MenuFlyoutItem Text="Lock Password Viewing"/>
                <MenuFlyoutItem Text="Change Viewing Password"/>
            </MenuFlyoutSubItem>
            <MenuFlyoutSubItem Text="Password Database">
                <MenuFlyoutItem Text="Create New Database"/>
                <MenuFlyoutItem Text="Change Current Database"/>
                <MenuFlyoutItem Text="Change Database Password"/>
            </MenuFlyoutSubItem>
        </MenuBarItem>
        <MenuBarItem Text="Exit" />

But now I want to give MenuBarItems functions when clicked on. For instance, How would I close the form when a user clicks on the Exit MenuBarItem?

I tried adding Command= but that didn't seem to work. Any help is appreciated. Thanks.


Answers (3)