CommunityToolkit / dotnet

.NET Community Toolkit is a collection of helpers and APIs that work for all .NET developers and are agnostic of any specific UI platform. The toolkit is maintained and published by Microsoft, and part of the .NET Foundation.
https://docs.microsoft.com/dotnet/communitytoolkit/?WT.mc_id=dotnet-0000-bramin
Other
2.99k stars 294 forks source link

[MVVM] Using ObservableCollection with CollectionView IsGrouped="True" causes crash #786

Closed megukaphii closed 11 months ago

megukaphii commented 11 months ago

Describe the bug

When using a CollectionView where the ItemSource is set to a binding of type ObservableCollection, and IsGrouped is set to True, the app crashes if the ObservableCollection is updated such that: there are more than 2 items in the first group, or there is more than 1 item in any subsequent group.

I tested this by copy+pasting from Microsoft's official CollectionView grouping docs in a brand new project: https://learn.microsoft.com/en-us/dotnet/maui/user-interface/controls/collectionview/grouping Please find said project here: https://github.com/megukaphii/GroupedCollectionViewBug

Regression

No response

Steps to reproduce

1. Download the repo linked above: https://github.com/megukaphii/GroupedCollectionViewBug
2. Run the project on Windows and click the "Load Animals" button
3. Note that the program does not crash with only 1 animal in the second "Monkeys" group, and that it does crash if you subsequently add a third animal to the "Bears" group

Expected behavior

The app does not crash.

Screenshots

No response

IDE and version

Rider

IDE version

RD-233.11361.12

Nuget packages

Nuget package version(s)

8.2.2

Additional context

No response

Help us help you

No, just wanted to report this

megukaphii commented 11 months ago

Sorry, I'm using the CommunityToolkit and missed that the ObservableCollection isn't actually part of it! Please ignore this.