Thomas Carlton
Thomas Carlton

Reputation: 5968

.Net Maui a picker with multiple selection?

Is there in MAUI a picker with multiple selection ? I couldn't find any.

So far, am using the standard one. but it doesn't have the ability to select multiple values.

<Picker x:Name="MyPicker" VerticalOptions="Center"></Picker>

In the documentation here neither, they don't talk about any multiple selection.

Upvotes: 8

Views: 4717

Answers (2)

Mohamed Yousuf
Mohamed Yousuf

Reputation: 21

You can use the Uranium UI control - MultiPickerField. It has some limitations but it does serves the purpose.

Upvotes: 1

I Am The Blu
I Am The Blu

Reputation: 863

In .NET MAUI, you can use the MultiSelectCollectionView control to provide a picker with multiple selection capabilities. The MultiSelectCollectionView control allows users to select multiple items from a collection.

Install the Microsoft.Maui.Controls.Compatibility package from NuGet.

And in the xaml file add the namespace for the newly added nuget & use the MultiSelectCollectionView as:

--------------------------------------------------------------------------------
xmlns:controls="clr-namespace:Microsoft.Maui.Controls.Compatibility;assembly=Microsoft.Maui.Controls.Compatibility"
xmlns:local="clr-namespace:YourNamespace"
--------------------------------------------------------------------------------
<controls:MultiSelectCollectionView
    x:Name="multiSelectCollectionView"
    SelectionMode="Multiple">
    <controls:MultiSelectCollectionView.ItemsSource>
        <x:Array Type="{x:Type x:String}">
            <x:String>Option 1</x:String>   // Sample Array
            <x:String>Option 2</x:String>
            <x:String>Option 3</x:String>
            <x:String>Option 4</x:String>
        </x:Array>
    </controls:MultiSelectCollectionView.ItemsSource>
</controls:MultiSelectCollectionView>

And in the code behind you can access it as:

var selectedItems = multiSelectCollectionView.SelectedItems.Cast<string>().ToList();

Upvotes: 3

Related Questions