roubachof / Sharpnado.CollectionView

A performant list view supporting: grid, horizontal and vertical layout, drag and drop, and reveal animations.
The Unlicense
244 stars 30 forks source link

ItemsSource does not notice changes to underlying ObservableCollection #26

Closed ewerspej closed 3 years ago

ewerspej commented 3 years ago

Platform (please complete the following information):

Describe the bug The ItemsSource bindable property of the HorizontalListView is implemented with BindingMode.TwoWay, but TwoWay-Binding actually doesn't work properly. The HorizontalListView never sees any changes to the underlying ObservableCollection which is bound to it.

This is a problem for the following reasons:

  1. Refreshes on the ObservableCollection (e.g. when new data is loaded from a Backend) are never noticed
  2. Undoing Drag & Drop events, such as illegal moves, cannot be performed

This issue is quite urgent, because it is blocking a feature I'm currently working on.

To Reproduce Steps to reproduce the behavior:

  1. Setup a HorizontalListView
  2. Add an ObservableCollection to the ViewModel
  3. Bind to the ObservableCollection as the HLV's ItemsSource
  4. Change the ObservableCollection from within the ViewModel (e.g. add a button to move an item around)
  5. You'll see that the HorizontalListView doesn't notice the change.
roubachof commented 3 years ago

mmmh seems weird since binding to an ObservableCollection is supported, all the collection changed events are processed: https://github.com/roubachof/Sharpnado.HorizontalListView/blob/main/Sharpnado.HorizontalListView.Droid/Renderers/HorizontalList/AndroidHorizontalListViewRenderer.RecycleViewAdapter.cs

ewerspej commented 3 years ago

It doesn't work in my solution and it also doesn't work in your sample app.

ewerspej commented 3 years ago

ah, I see that you do not process the Move and Replace enum values of the CollectionChanged event's NotifyCollectionChangedEventArgs - you only check for Add, Remove and Reset. Thanks for the quick reply, by the way.

The reason I noticed this in the first place is that I want to implement some restrictions to the Drag & Drop. Ideally, an operation could be cancelled, but I guess that would be a Feature Request.

roubachof commented 3 years ago

Just so you know I am implementing right now move and replace actions. Reset is already taken care of.

ewerspej commented 3 years ago

@roubachof awesome, thanks!