BindableLayout loses sync with source if RaiseChild is used [Bug]
#8.724 geöffnet am 02.12.2019
Repository-Metriken
- Stars
- (5.644 Sterne)
- PR-Merge-Metriken
- (Keine gemergten PRs in 30 T)
Beschreibung
Description
During handling of NotifyCollectionChangedEventArgs BindableLayout honor only indexes of new/old items. 'RaiseChild' under the hood just reorders Layout's children collection and put certain element at the top of the Layout.InternalChildren. In that moment BindableLayout loses sync with source since layout's children collection was reordered though its BindableLayout.ItemsSource remains unchanged. It leads to issues when some item removed from original source collection - this item has different index in the Layout.InternalChildren and wrong item view is removed from the Layout.
Possible solution: handling NotifyCollectionChangedEventArgs Remove action this way:
(item, index) => layout.Children.Remove(GetViewByBindingContext(item))
instead of
(item, index) => layout.Children.RemoveAt(index) (source)
There is reproduction project attached. Reproduced on UWP platform. Didn't test Android and iOS.
Steps to Reproduce
- Create AbsoluteLayout (or any other layout with RaiseChild method available)
- Bind BindableLayout to some source which implements INotifyCollectionChanged
- Use RaiseChild method of the layout.
- Remove certain item from original collection
Sample app description:
- AbsoluteLayout with BindableLayout set to ObservableCollection
- ListView bound to the same collection
- Click on the AbsoluteLayout's item view calls AbsoluteLayout.RaiseChild (items will overlap each other) 4."Remove" button on ListView's item removes item from the source - ObservableCollection
Expected Behavior
Item view, bound to removed item should be removed from the layout.
Actual Behavior
Item view removed from the layout does not match item removed from the source collection.
Basic Information
- Version with issue: 4.3.0.991211
- Last known good version: N/A
- IDE: VisualStudio 2019
- Platform Target Frameworks:
- iOS: not tested
- Android: not tested
- UWP: 10.0.16299.0
- Android Support Library Version:
- Nuget Packages:
- Affected Devices:
Screenshots
