[Bug] CollectionView Redundant Binding #12202
Comments
Sorry but i m not understanding the question , can you explain a little better, for example what do you expect the output to be when add remove items. right now i see this and it looks fine:
|
This is what I get: [ First Run, initial item count of 2 ] [ Remove Second Item ] [ Remove remaining Item ] [ Add an Item ] [ Add next Item ] EDIT: |
I tried on Android and it functions as expected, no unnecessary setting of the binding context, and it even sets to null when the corresponding object is removed from ItemSource. Any ideas? |
I found a clue here: #7152 (comment) |
this might be worth investigating, @hartez |
We are also experiencing the same problem. In the CollectionView's ItemTemplate, we're using custom layout (e.g., FlexLayout). When we update the ItemsSource at runtime, the old items binding is not disposed of or set to null. As a result, our layout duplicated in the view. If we set the BindingContext of the removed items to null, the binding issue may be resolved. However, the old items are maintained in memory. The custom layout object grew in memory with each update of ItemsSource. |
Description
CollectionView sets ItemSource objects as BindingContext of multiple Views created thru the ItemTemplate in initial binding of ItemSource, adding and removing items in ItemSource.
EDIT:
It seems that CollectionView is [pre]caching item views but many are unnecessarily assigned their binding context to existing objects in ItemSource.
Steps to Reproduce
Observe the Debug output in initial binding, adding and removing items in the sample project.
Expected Behavior
Objects from ItemSource is set as binding context for only a single item view instantiated from ItemTemplate (or reused from cache) within the CollectionView. When an object is removed from ItemSource, the binding context of the corresponding item view should be set to null.
Actual Behavior
ItemSource objects are set as BindingContext of multiple Views created thru the ItemTemplate in initial binding of ItemSource, adding and removing items in ItemSource. When an object is removed from ItemSource, the binding context of the corresponding item view is not set to null.
Basic Information
CollectionView_Redundant_Binding.zip
Last known good version: n/a
The text was updated successfully, but these errors were encountered: