maui icon indicating copy to clipboard operation
maui copied to clipboard

[Windows] Fixed CollectionView with grouping fails to add items when a footer template is present or crashes when removing data.

Open NirmalKumarYuvaraj opened this issue 1 year ago • 1 comments

Root Cause

  • Add - When a CollectionView contains grouping and a footer template, we create a new List and add the footer to the list if the footer's item template type is not an IList. This prevents events such as CollectionChanged or INotifyCollectionChanged from being triggered on the original collection. As a result, when a new item is added to the collection, it is not reflected in the view.

  • 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 avatar Sep 23 '24 09:09 NirmalKumarYuvaraj

@NirmalKumarYuvaraj Could you rebase and fix the conflict? Thanks in advance.

jsuarezruiz avatar Oct 23 '24 09:10 jsuarezruiz

@NirmalKumarYuvaraj Could you rebase to fix the conflicts?

jsuarezruiz avatar Jan 10 '25 07:01 jsuarezruiz

/azp run

jfversluis avatar Jan 23 '25 14:01 jfversluis

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Jan 23 '25 14:01 azure-pipelines[bot]

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Jan 28 '25 11:01 azure-pipelines[bot]

/azp run

jsuarezruiz avatar Feb 26 '25 07:02 jsuarezruiz

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Feb 26 '25 07:02 azure-pipelines[bot]

The test JustWhalingAwayOnTheCollectionViewWithAddsAndClearsShouldNotCrash is crashing: The app was expected to be running still, investigate as possible crash I 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.

image

NirmalKumarYuvaraj avatar Mar 03 '25 07:03 NirmalKumarYuvaraj

/azp run

jsuarezruiz avatar Mar 25 '25 07:03 jsuarezruiz

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Mar 25 '25 07:03 azure-pipelines[bot]

@NirmalKumarYuvaraj Could you fix the conflict?

jsuarezruiz avatar Jun 09 '25 07:06 jsuarezruiz

@NirmalKumarYuvaraj Could you fix the conflict?

@jsuarezruiz , I have rebased the branch. please let me know if you have any concern.

NirmalKumarYuvaraj avatar Jun 09 '25 08:06 NirmalKumarYuvaraj

/azp run

jsuarezruiz avatar Jun 13 '25 11:06 jsuarezruiz

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Jun 13 '25 11:06 azure-pipelines[bot]

@jsuarezruiz friendly ping, no related issues on CI

bronteq avatar Jun 24 '25 16:06 bronteq

Would be great if this could be planned into a service release version

baaaaif avatar Jul 09 '25 17:07 baaaaif

/rebase

jsuarezruiz avatar Jul 15 '25 12:07 jsuarezruiz

/azp run

jsuarezruiz avatar Jul 15 '25 12:07 jsuarezruiz

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Jul 15 '25 12:07 azure-pipelines[bot]

@jsuarezruiz , CI is green

NirmalKumarYuvaraj avatar Jul 17 '25 07:07 NirmalKumarYuvaraj

This is another related issue https://github.com/dotnet/maui/issues/20037

bronteq avatar Aug 22 '25 13:08 bronteq

/rebase

jsuarezruiz avatar Oct 31 '25 12:10 jsuarezruiz