Skip to content

Conversation

@KarthikRajaKalaimani
Copy link
Contributor

@KarthikRajaKalaimani KarthikRajaKalaimani commented Nov 24, 2025

Issue Details:

The user has implemented a VisualStateManager for the Grid.BackgroundColor (which is Item template in collectionview) property to apply a selected background color. However, on the iOS platform, the selected item’s background color changes unexpectedly—from LightSkyBlue back to the default gray—when scrolling from bottom to top.

Root Cause:

iOS uses a native UICollectionView, which reuses cells by default. When the collection view loads scrollable items, it initially creates only the cells required for the visible area. As the user scrolls, previously created cells are reused or recreated for new items.
When scrolling back to a previously selected item, the corresponding cell is reused and recreated. At this point, the selected cell incorrectly receives the default gray background color, because in the GetCell method of the ItemsViewController2 class (line 112). the reused cell is instantiated with the default background color defined in the constructor of ItemsViewCell2. The selected background color is not re-applied to the reused cell, causing the color to appear as gray.

Description of Change:

To ensure the correct selected state is applied when a cell is reused:

  • UpdateVisualStates() is called to re-apply the appropriate VisualStateManager styles to the template views- but only for selected cells.
  • UpdateSelectionColor() is invoked to clear the default selection background—but only for selected cells.
    These updates were added to the BindVirtualView method in the TemplatedCell2 class to ensure the correct selected background color is consistently applied, even when cells are reused.

Tested the behavior in the following platforms.

The test case for this scenario is not included in this PR, because the issue occurs very randomly. So, manually tested the fix.

  • Android
  • Windows
  • iOS
  • Mac

Reference:

N/A

Issues Fixed:

Fixes #32493

Closes #32795

Screenshots

Before After
BeforeFix.mov
AfterFix.mov

…r scrolling when deploying ManualMaui Demo project on iOS 26.1
@dotnet-policy-service dotnet-policy-service bot added community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration labels Nov 24, 2025
@sheiksyedm sheiksyedm added area-controls-collectionview CollectionView, CarouselView, IndicatorView collectionview-cv2 labels Nov 24, 2025
@sheiksyedm sheiksyedm changed the title Fixed Selected item color changes from lightskyblue to lightgray after scrolling when deploying ManualMaui Demo project on iOS 26.1 [iOS][CV2]Fixed Selected item color changes from lightskyblue to lightgray after scrolling when deploying ManualMaui Demo project on iOS 26.1 Nov 24, 2025
@sheiksyedm sheiksyedm marked this pull request as ready for review November 24, 2025 12:44
Copilot AI review requested due to automatic review settings November 24, 2025 12:44
@sheiksyedm
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an iOS-specific issue where CollectionView selected item background colors defined via VisualStateManager incorrectly revert to the default gray color when cells are reused during scrolling. The fix ensures that when a cell is reused for a selected item, the correct visual state and selection color are reapplied.

Key Changes:

  • Added logic to reapply VisualStateManager states and selection colors when binding a cell that is in the selected state
  • The fix is specific to iOS CollectionView2 implementation (Items2 handlers)

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

@jfversluis jfversluis changed the base branch from main to inflight/current November 27, 2025 12:01
@jfversluis jfversluis merged commit 757600b into dotnet:inflight/current Nov 27, 2025
1 check passed
@jfversluis jfversluis added this to the .NET 10.0 SR2 milestone Nov 27, 2025
PureWeen pushed a commit that referenced this pull request Dec 3, 2025
…r scrolling when deploying ManualMaui Demo project on iOS 26.1 (#32822)

Fix optimized

Update src/Controls/src/Core/Handlers/Items2/iOS/TemplatedCell2.cs

Co-authored-by: Copilot <[email protected]>
github-actions bot pushed a commit that referenced this pull request Dec 5, 2025
…r scrolling when deploying ManualMaui Demo project on iOS 26.1 (#32822)

Fix optimized

Update src/Controls/src/Core/Handlers/Items2/iOS/TemplatedCell2.cs

Co-authored-by: Copilot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-controls-collectionview CollectionView, CarouselView, IndicatorView collectionview-cv2 community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[iOS][CV2]Selected item color changes from lightskyblue to lightgray after scrolling when deploying ManualMaui Demo project on iOS 26.1

3 participants