Hello,
You can do this by adding the picker's ItemSource to a System.Collections.ObjectModel.ObservableCollection
For example, you have a Picker like following code.
<Picker x:Name="picker"
Title="Select a monkey" >
Then, you can create a new ObservableCollection, add data in it and set the picker's ItemSource.
ObservableCollection<string> values = new ObservableCollection<string>();
public MainPage()
{
InitializeComponent();
for (int i = 0;i<5;i++)
{
values.Add(i.ToString());
}
picker.ItemsSource = values;
}
I used a Button click event to make a test, if you want to change the third one's value in the Picker. You can set it directly. this value in the DataPicker will be changed.
private async void OnCounterClicked(object sender, EventArgs e)
{
values[2] = "test";}
}
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.