Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MvvmCross MvxListView not refreshing on item delete

When I remove an item from my list, the MvxListView does not refresh.

My list (nothing fancy):

private List<Item> items = new List<Item>();
public List<Item> Items 
{ 
     get { return items; } 
     set { items = value; RaisePropertyChanged(() => Items); } 
}

The code that doesn't work:

Items.RemoveAll(x => x.Id == item.Id);
RaisePropertyChanged(() => Items); 

Code that does work:

Items = Items.Where(x => x.Id != item.Id).ToList();

It seems like the RaisePropertyChanged() function does not have the desired effect when being called from a isolated function within the viewmodel, but why?

like image 842
MichielDeRouter Avatar asked Dec 01 '25 10:12

MichielDeRouter


1 Answers

You need to use an ObservableCollection to make the MvxListView update the content.

private ObservableCollection<Item> items = new ObservableCollection<Item>();
public ObservableCollection<Item> Items 
{ 
     get { return items; } 
     set { items = value; RaisePropertyChanged(() => Items); } 
}
like image 88
Martijn00 Avatar answered Dec 03 '25 23:12

Martijn00



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!