Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ItemsSource does not notice changes to underlying ObservableCollection #26

Closed
ewerspej opened this issue May 19, 2021 · 5 comments
Closed

Comments

@ewerspej
Copy link

ewerspej commented May 19, 2021

Platform (please complete the following information):

  • OS: Both

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
Copy link
Owner

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
Copy link
Author

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

@ewerspej
Copy link
Author

ewerspej commented May 19, 2021

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
Copy link
Owner

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

@ewerspej
Copy link
Author

ewerspej commented Jun 3, 2021

@roubachof awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants