ListView doesn't handle NotifyCollectionChangedAction.Replace with different number of items in old and new. #9607
Labels
area-Lists
ListView, GridView, ListBox, etc
bug
Something isn't working
team-Controls
Issue for the Controls team
Describe the bug
When a ListView databinds to a collection that implements INotifyCollectionChanged, and the collection invokes a CollectionChanged event with NotifyCollectionChangedAction.Replace with different number of items in newItems and oldItems, the ListView does not update.
I uploaded a simple test app here: https://github.com/euju-ms/CollectionChangedReplaceBug
Essentially, when my testCollection gains an item, it fires a replace event
E.g. [A, B] => [A, B, C]
In this case, ListView should update its visual from showing A, B to showing A, B, C, but it doesn't change in visual at all.
Replace event with same number of items in newItems and oldItems seem to work fine.
`
public void AddByReplace(string new Item)
{
_list.Add(newItem); // _list is a List.
}
`
<ListView Header="TestCollection" ItemsSource="{x:Bind testCollection, Mode=OneWay}" ItemTemplate="{StaticResource StringDataTemplate}" /> <!-- StringDataTemplate is just a TextBlock -->
I couldn't find any restriction on "Replace" CollectionChanged event needing to have the same number of items in newItems and oldItems, so I'm filing this as a bug here.
E.g. NotifyCollectionChangedEventArgs constructor for Replace does not check for the number of items.
Steps to reproduce the bug
Expected behavior
Items on the left (below "TestCollection") should change whenever "Replace (2->3)" button is clicked.
Screenshots
On startup:
Clicking "Replace (2 -> 3)"
Actual:
Expected result is that you see three items below TestCollection, "hello", "world", "New Text 0".
NuGet package version
None
Windows version
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: