Hello,
Welcome to our Microsoft Q&A platform!
An alternative I can think of would be to just clear the list and reinsert new objects but that seems wasteful.
After creating a ViewModel class and setting BindingContext
for the page, please make sure the data collection you want to update is from the bindingContext.
Check the following code:
public partial class TestPage : ContentPage
{
TestPageViewModel viewModel;
public TestPage()
{
InitializeComponent();
viewModel = new TestPageViewModel();
BindingContext = viewModel;
}
private async void Button_Clicked(object sender, EventArgs e)
{
//update the data
viewModel.BindableItems.Add(new BindableItem{ ... });
}
}
public class TestPageViewModel
{
public ObservableCollection<BindableItem> BindableItems { get; set; }
public TestPageViewModel()
{
DataCollection = new ObservableCollection<BindableItem>();
//add the data
}
}
Best Regards,
Jarvan Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
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.