[Android, iOS, Mac] Fix inconsistent Background vs BackgroundColor behavior in CollectionView selection with VSM#32669
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an inconsistency in CollectionView where Background and BackgroundColor properties behave differently during item selection when using VisualStateManager (VSM). The root cause was that IsUsingVSMForSelectionColor() only checked for BackgroundColorProperty but not BackgroundProperty, causing the default platform selection color to be applied when VSM used the Background property.
Key changes:
- Updated
IsUsingVSMForSelectionColor()to check both BackgroundProperty and BackgroundColorProperty - Added comprehensive UI test demonstrating the fix
- Included screenshot verification for iOS and Android
Reviewed Changes
Copilot reviewed 5 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Controls/src/Core/Handlers/Items/iOS/TemplatedCell.cs | Added BackgroundProperty check in iOS implementation |
| src/Controls/src/Core/Handlers/Items2/iOS/TemplatedCell2.cs | Added BackgroundProperty check in iOS Items2 implementation |
| src/Controls/src/Core/Handlers/Items/Android/TemplatedItemViewHolder.cs | Added BackgroundProperty check in Android implementation |
| src/Controls/tests/TestCases.HostApp/Issues/Issue32348.cs | Test page demonstrating Background vs BackgroundColor with VSM |
| src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue32348.cs | NUnit test with screenshot verification |
| src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/*.png | iOS screenshot baseline |
| src/Controls/tests/TestCases.Android.Tests/snapshots/android/*.png | Android screenshot baseline |
| if (setter.Property.PropertyName == VisualElement.BackgroundColorProperty.PropertyName || | ||
| setter.Property.PropertyName == VisualElement.BackgroundProperty.PropertyName) |
There was a problem hiding this comment.
[nitpick] Consider extracting the property name checks into a local variable or using a helper method to reduce duplication. This pattern is repeated across three files (iOS TemplatedCell.cs, iOS TemplatedCell2.cs, and Android TemplatedItemViewHolder.cs), making it harder to maintain if additional background-related properties need to be checked in the future.
|
/azp run MAUI-UITests-public |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/rebase |
a832002 to
9877f9f
Compare
|
/azp run MAUI-UITests-public |
|
Azure Pipelines successfully started running 1 pipeline(s). |
…onView selection (#32669) added testcase. Update Issue32348.cs Update Issue32348.cs added android snap. added ios snap Added windows and mac snapshots.
…onView selection (#32669) added testcase. Update Issue32348.cs Update Issue32348.cs added android snap. added ios snap Added windows and mac snapshots.
…onView selection (#32669) added testcase. Update Issue32348.cs Update Issue32348.cs added android snap. added ios snap Added windows and mac snapshots.
…onView selection (#32669) added testcase. Update Issue32348.cs Update Issue32348.cs added android snap. added ios snap Added windows and mac snapshots.
…onView selection (#32669) added testcase. Update Issue32348.cs Update Issue32348.cs added android snap. added ios snap Added windows and mac snapshots.
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Issue Detail
When using a CollectionView with VisualStateManager, Background and BackgroundColor behave differently during selection.
Root Cause
IsUsingVSMForSelectionColor() checks only for BackgroundColorProperty and does not check for BackgroundProperty. When VSM uses Background, the method returns false, so iOS/Android apply their default selection color.
Description of Change
Updated IsUsingVSMForSelectionColor() to check for both background properties so that the default selection overlay is disabled when VSM applies a selection background.
Tested the behavior in the following platforms
Issues Fixed
Fixes #32348
Screenshots
iOS:
32348BeforeiOS.mov
32348AfteriOS.mov
Android:
32348AndroidBefore.mov
32348AndroidAfter.mov