How do I set the selected item in a Picker in C# code-behind?

Platform: .NET MAUI| Category: Controls

You can set the selected item in C# code-behind using the SelectedIndex property or the SelectedItem property:

public MainPage()
{
	InitializeComponent();
       var myPicker = new Picker();
       myPicker.ItemsSource = new List<string> {"Mark,Annie,Rose"};        
       Content = myPicker;
       myPicker.SelectedIndex = 2; 
       myPicker.SelectedItem = "Rose";    
}

Share with

Related FAQs

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

Please submit your question and answer.