How do I create sub-menu items in XAML?

Platform: .NET MAUI| Category: Controls

You can create sub-menu items by following this code,
XAML:

<Label x:Name="label"
       Text="Right-click to choose color">
        <FlyoutBase.ContextFlyout >
            <MenuFlyout  >
                   <MenuFlyoutItem  Text="Black"                                 
                                    Clicked="MenuFlyoutItem_Clicked"
                                    CommandParameter="Black" />
                <MenuFlyoutSubItem  Text="Light" >
                    <MenuFlyoutItem Text="Blue"
                                    Clicked="MenuFlyoutItem_Clicked"
                                    CommandParameter="LightBlue" />
                    <MenuFlyoutItem Text="Coral"
                                    Clicked="MenuFlyoutItem_Clicked"
                                    CommandParameter="LightCoral" />
                    <MenuFlyoutItem Text="Cyan"
                                    Clicked="MenuFlyoutItem_Clicked"
                                    CommandParameter="LightCyan" />
                </MenuFlyoutSubItem>
                <MenuFlyoutSubItem  Text="Dark">
                    <MenuFlyoutItem Text="Blue"
                                    Clicked="MenuFlyoutItem_Clicked"
                                    CommandParameter="DarkBlue" />
                    <MenuFlyoutItem Text="Cyan"
                                    Clicked="MenuFlyoutItem_Clicked"
                                    CommandParameter="DarkCyan" />
                    <MenuFlyoutItem Text="Magenta"
                                    Clicked="MenuFlyoutItem_Clicked"
                                    CommandParameter="DarkMagenta" />
                </MenuFlyoutSubItem>
            </MenuFlyout>
        </FlyoutBase.ContextFlyout>
    </Label>

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.