How can I include a Picker as a MenuItem in .NET MAUI?

Viewed 19

Is it possible to add a dropdown Picker into a MAUI Flyout? I have a requirement to make a global choice available easily to all Pages. I know I could create a Settings Page, but it would be easier for the users to do it in the menu.

I have inserted the Picker sample code into a MenuItem, but am getting this error:

XLS0502 The type 'MenuItem' does not support direct content.

Is there some other way to do this, or is cross-platform compatibility somehow limiting our ability here?

<?xml version="1.0" encoding="UTF-8" ?>
<Shell
    x:Class="SAE.AppShell"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:views="clr-namespace:SAE.MVVM.Views"
    Shell.FlyoutBehavior="Locked"
    Shell.FlyoutBackground="DarkGray">

    <FlyoutItem Title="Items" Icon="building_regular.png">
        <Tab>
            <ShellContent ContentTemplate="{DataTemplate views:Items}" />
        </Tab>
    </FlyoutItem>

    <MenuItem Text="Color">
            <Picker Title="Color"
                VerticalOptions="CenterAndExpand"
                Margin="10, 0"
                SelectedIndexChanged="OnPickerSelectedIndexChanged">
                <Picker.Items>
                    <x:String>Aqua</x:String>
                    <x:String>Black</x:String>
                    <x:String>Blue</x:String>
                    <x:String>Fuchsia</x:String>
                    <x:String>Gray</x:String>
                    <x:String>Green</x:String>
                    <x:String>Lime</x:String>
                    <x:String>Maroon</x:String>
                    <x:String>Navy</x:String>
                    <x:String>Olive</x:String>
                    <x:String>Purple</x:String>
                    <x:String>Red</x:String>
                    <x:String>Silver</x:String>
                    <x:String>Teal</x:String>
                    <x:String>White</x:String>
                    <x:String>Yellow</x:String>
                </Picker.Items>
            </Picker>
    </MenuItem>


</Shell>
0 Answers
Related