Reputation: 15
I have a picker:
<Picker Title="Status" x:Name="pickerStatus">
<Picker.Items>
<x:String>In Progress</x:String>
<x:String>Completed</x:String>
<x:String>Dropped</x:String>
<x:String>Plan To Take</x:String>
</Picker.Items>
The required value is already stored in a database as a Text value. How do I display a picker on an editable page to load that selected text value from the database into the edit page picker? I've tried:
pickerStatus.SelectedItem = _courseObject.Status;
Upvotes: 1
Views: 120
Reputation: 1799
This approach is made for code-behind, if you intend to use ViewModels I can provide a more in-depth answer. But for your case this works:
List<string> pickerStates = new List<string>
{
"In Progress",
"Completed",
"Dropped",
"Plan To Take"
};
pickerStatus.ItemsSource = pickerStates;
pickerStatus.SelectedIndex = pickerStates
.FindIndex(status => status == _courseObject.Status);
Upvotes: 2