Skip to content

AdvancedCollectionView insert at bad index #4465

@texaclou

Description

@texaclou

Describe the bug

Hello, this is my first issue here, I hope I dot it the right way.

With a AdvancedCollectionView used with a Filter and without SortDescription,
When a add a item to the source collection, the item is not inserted at the end of the CollectionView,
it inserted before the last item.

With no filter there is no problem

Steps to reproduce

ObservableCollection<int> sourceList = new ()
 {
       1,2,3,4,5
 };

AdvancedCollectionView acv = new(sourceList, false);

//filter to keep only even integers
acv.Filter = x => (int)x % 2 == 0;
            
Assert.AreEqual("24", String.Join("", acv));
// succeed

sourceList.Add(6);

Assert.AreEqual("246", String.Join("", acv)); 
//failed  result = 264

Expected behavior

The new item should be inserted at the end

Windows Build Number

  • Windows 10 1809 (Build 17763)
  • Windows 10 1903 (Build 18362)
  • Windows 10 1909 (Build 18363)
  • Windows 10 2004 (Build 19041)
  • Windows 10 20H2 (Build 19042)
  • Windows 10 21H1 (Build 19043)
  • Windows 11 21H2 (Build 22000)
  • Other (specify)

Windows Community Toolkit version

7.1.0

Visual Studio Version

2022

Device form factor

Desktop

Additional context

If there is no filter the insertion index is defined like this, so in this case it work correctly :

I think the issue is from this line, in the HandleItemAdded method,
when there is a filter the new item index is define like this :

Help us help you

Yes, but only if others can assist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛An unexpected issue that highlights incorrect behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions