How can I handle the selection change event of a Picker in XAML?

Platform: .NET MAUI| Category: Controls

To handle the selection change event of a Picker in XAML:
XAML:

<Picker x:Name="myPicker" SelectedIndexChanged="OnSelectedIndexChanged" >
        <Picker.ItemsSource>
            <x:Array Type="{x:Type x:String}">
                <x:String>Mark</x:String>
                <x:String>Jack</x:String>
                <x:String>Annie</x:String>
            </x:Array>
        </Picker.ItemsSource>
</Picker>

C#

private void OnSelectedIndexChanged(object sender, EventArgs e) 
{
        var selectedValue = myPicker.SelectedItem.ToString();
}

Share with

Related FAQs

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

Please submit your question and answer.