maui
maui copied to clipboard
[Windows] Fixed CollectionView with grouping fails to add items when a footer template is present or crashes when removing data.
Root Cause
-
Add - When a CollectionView contains grouping and a footer template, we create a new List
-
Clear - When clearing the collection and adding items at runtime, a COM exception occurs when items are grouped. This happens because the OnItemsVectorChanged event is triggered whenever there is a change in the item collection, causing ListViewBase.ScrollIntoView to be called from a background thread, which leads to the COM exception.
Description of Change
Windows
-
Add - Reverting the changes made in PR #24205 caused the exception . This exception occurred due to the triggering of the TemplateCollectionChanged event, which was introduced during the implementation of drag-and-drop functionality for the CollectionView in PR #3768. Adding the footer to the items triggers the TemplateCollectionChanged event, which incorrectly adds the footer as a new item in the collection. Since the footer template is not the same type as the items in the original collection, this results in the exception. To resolve this, we can ignore the addition of the footer template to the ItemsSource.
-
Clear - Calling ListViewBase.ScrollIntoView after a slight delay helps avoid exceptions and ensures synchronized updates.
Validated the behaviour in the following platforms
- [x] Android
- [x] Windows
- [ ] iOS
- [ ] Mac
iOS and Mac has issues - #17969
Issues Fixed
Fixes #24866 Fixes #19721
Output
Windows
Before
https://github.com/user-attachments/assets/2813d618-2c9d-4700-af20-8402b0779597
After
https://github.com/user-attachments/assets/bb96519e-5a70-47a8-a872-d61ac2cf8f4f
@NirmalKumarYuvaraj Could you rebase and fix the conflict? Thanks in advance.
@NirmalKumarYuvaraj Could you rebase to fix the conflicts?
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
Azure Pipelines successfully started running 3 pipeline(s).
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
The test JustWhalingAwayOnTheCollectionViewWithAddsAndClearsShouldNotCrash is crashing:
The app was expected to be running still, investigate as possible crashI think could be related with the changes, could you take a look?
@jsuarezruiz , I have updated the code changes and ensured the test case is passing locally. Please let me know if you have any concerns.
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
@NirmalKumarYuvaraj Could you fix the conflict?
@NirmalKumarYuvaraj Could you fix the conflict?
@jsuarezruiz , I have rebased the branch. please let me know if you have any concern.
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
@jsuarezruiz friendly ping, no related issues on CI
Would be great if this could be planned into a service release version
/rebase
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
@jsuarezruiz , CI is green
This is another related issue https://github.com/dotnet/maui/issues/20037
/rebase