Skip to content

ListCollectionView generating bad NewStartingIndex on LiveSorting #11257

@nalywa

Description

@nalywa

When using a ListCollectionView with live sorting enabled, occasionally the CollectionChanged event will emit a NotifyCollectionChangedAction.Move notification where the NotifyCollectionChangedEventArgs.NewStartingIndex property doesn't match the actual index of the item in the collection found with ListCollectionView.IndexOf(object item).

If the collection view is used as an items source for a WPF component such as ListBox, this can result in incorrect sorting behavior or duplicate items appearing.

This seems to only occur for large collections (hundreds of items) where most of them have been marked for re-sort, presumably enough to meet ListCollectionView.LiveSortingDensityThreshold and trigger the LiveShapingList.RestoreLiveSortingByInsertionSort(...) code path.

I've attached a failing unit test demonstrating the problem. The expected behavior is that observing CollectionChanged events would be enough to keep an external collection in sync with the ListCollectionView items.

ListCollectionViewTests.cs.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions