1
votes

I need to refresh an MvxListView if I add an item to the ItemsSource and also if some of the data changes in the item. The ItemsSource is sorted in reverse so when I add an item I'm using

private void OnItemAdded(object sender, ObjectEventArgs e)
{
  ItemDataList.Insert(0, new ItemData((Item)e.Object));
}

When I use an ObservableCollection and the list is positioned at the top and I insert an item at the top the list refreshes, the new item visible at the top and all other items moved down.

If I use a BindingList then the list is not refreshed until I scroll it. RaiseListChangedEvents is set to true so I'm expecting that it will refresh.

I can't use ObservableCollection because I also need to refresh items when their data changes - this is working with BindingList and ItemData derived from MvxNotifyPropertyChanged.

Am I correct in doing this. Should MvxListView work with BindingList?

Thanks, Jonathan

2

2 Answers

0
votes

INotifyCollectionChanged is the way the MvxAdapter binds to collections - see https://github.com/MvvmCross/MvvmCross/blob/v3.1/Cirrious/Cirrious.MvvmCross.Binding.Droid/Views/MvxAdapter.cs#L136

Similarly in iOS for MvxTableViewSource - https://github.com/MvvmCross/MvvmCross/blob/v3.1/Cirrious/Cirrious.MvvmCross.Binding.Mac/Views/MvxTableViewSource.cs#L56

As a result IBindingList (http://msdn.microsoft.com/en-us/library/system.componentmodel.ibindinglist(v=vs.110).aspx) is not supported by default. However, individual developers could easily add this if they wanted to - just extend the MvxAdapter above to subscribe to ListChanged events on any incoming IBindingList source.

0
votes

Maybe I'm going mad...it seems to work now I'm retesting it on the emulator.