Skip to content

CollectionView with Header Causes ArgumentOutOfRangeException on reordering to last index #18227

@sylac

Description

@sylac

Description

When using item reordering in CollectionView (#3768) with a defined Header, I encounter an ArgumentOutOfRangeException when attempting to move an item to the last position of the list. This issue is not present when the Header is omitted.

System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than or equal to the size of the collection. (Parameter 'index')'

Steps to Reproduce

  1. Create default MAUI project
  2. Define a CollectionView with a Header and ItemTemplate to xaml file:
<CollectionView
    x:Name="TestCollectionView"
    CanReorderItems="True"
    CanMixGroups="True">

    <CollectionView.Header>
        <Label Text="Header"/>
    </CollectionView.Header>
    
    <CollectionView.ItemTemplate>
        <DataTemplate>
            <Label Text="{Binding .}"/>
        </DataTemplate>
    </CollectionView.ItemTemplate>
</CollectionView>
  1. Populate ItemSource in xaml.cs file:
public TestCollectionViewPage()
{
    InitializeComponent();
    TestCollectionView.ItemsSource = new List<string>()
    {
        "Test label 1",
        "Test label 2",
        "Test label 3",
        "Test label 4",
        "Test label 5",
        "Test label 6",
    };
}
  1. Drag random Item from the middle to last position in the list

Link to public reproduction project repository

No response

Version with bug

7.0.96

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions