Fix for SwipeView Command Binding Issue in CollectionView Templates#32790
Merged
StephaneDelcroix merged 2 commits intodotnet:inflight/currentfrom Dec 2, 2025
Merged
Fix for SwipeView Command Binding Issue in CollectionView Templates#32790StephaneDelcroix merged 2 commits intodotnet:inflight/currentfrom
StephaneDelcroix merged 2 commits intodotnet:inflight/currentfrom
Conversation
… during content changes and updated the testcase.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a regression where SwipeItem command bindings fail when SwipeView is used within CollectionView templates. The root cause was a change in PR #30672 that inadvertently removed SwipeItems from the logical tree when content changes, breaking RelativeSource bindings. The fix modifies TemplateUtilities.OnContentChanged to selectively preserve SwipeItems (RightItems, LeftItems, TopItems, BottomItems) in the logical tree during content changes, ensuring bindings continue to work correctly.
Key changes:
- Modified
TemplateUtilities.OnContentChangedto add SwipeView-specific logic that preserves SwipeItems during content changes - Updated device test to verify SwipeView maintains all 5 logical children (Content + 4 SwipeItems)
- Added comprehensive unit test verifying SwipeItems remain in logical tree with proper parent relationships and binding context propagation
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Controls/src/Core/TemplateUtilities.cs | Added SwipeView-specific logic to preserve SwipeItems in the logical tree when content changes, using reference equality checks to identify and retain the four SwipeItems collections |
| src/Controls/tests/DeviceTests/Elements/SwipeView/SwipeViewTests.cs | Updated test assertion from expecting 1 logical child to 5 (Content + 4 SwipeItems), with clarifying comment |
| src/Controls/tests/Core.UnitTests/SwipeViewTests.cs | Added comprehensive unit test verifying SwipeItems preservation in logical tree, including parent relationships, binding context propagation, and RelativeSource binding resolution |
Contributor
|
/azp run MAUI-UITests-public |
|
Azure Pipelines successfully started running 1 pipeline(s). |
StephaneDelcroix
approved these changes
Dec 2, 2025
ab86f54
into
dotnet:inflight/current
161 of 169 checks passed
PureWeen
pushed a commit
that referenced
this pull request
Dec 3, 2025
…32790) * fix-32332-Made the code changes to skip the child removal to preserve SwipeItems. * fix-32332-Made the changes to preserve the SwipeItems in logical tree during content changes and updated the testcase.
PureWeen
pushed a commit
that referenced
this pull request
Dec 3, 2025
…32790) * fix-32332-Made the code changes to skip the child removal to preserve SwipeItems. * fix-32332-Made the changes to preserve the SwipeItems in logical tree during content changes and updated the testcase.
PureWeen
pushed a commit
that referenced
this pull request
Dec 3, 2025
…32790) * fix-32332-Made the code changes to skip the child removal to preserve SwipeItems. * fix-32332-Made the changes to preserve the SwipeItems in logical tree during content changes and updated the testcase.
PureWeen
pushed a commit
that referenced
this pull request
Dec 3, 2025
…32790) * fix-32332-Made the code changes to skip the child removal to preserve SwipeItems. * fix-32332-Made the changes to preserve the SwipeItems in logical tree during content changes and updated the testcase.
PureWeen
pushed a commit
that referenced
this pull request
Dec 3, 2025
…32790) * fix-32332-Made the code changes to skip the child removal to preserve SwipeItems. * fix-32332-Made the changes to preserve the SwipeItems in logical tree during content changes and updated the testcase.
github-actions bot
pushed a commit
that referenced
this pull request
Dec 5, 2025
…32790) * fix-32332-Made the code changes to skip the child removal to preserve SwipeItems. * fix-32332-Made the changes to preserve the SwipeItems in logical tree during content changes and updated the testcase.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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!
Root Cause:
The issue is caused by a change to TemplateUtilities.OnContentChanged() that switched from using self.InternalChildren.RemoveAt()to self.RemoveAt(). This change removes all SwipeItems (RightItems, LeftItems, TopItems, BottomItems) from the logical children tree when the SwipeView template is applied. When SwipeItems are removed from the logical tree, RelativeSource bindings cannot traverse the parent chain to find ancestor ViewModels, causing command bindings to fail.
Regression PR: #30672
Fix Description:
The fix involves modifying TemplateUtilities.OnContentChanged to preserve SwipeItems when SwipeView content changes. When a SwipeView's Content property changes, the method selectively removes only the old content while preserving SwipeItems (RightItems, LeftItems, TopItems, BottomItems) in the logical tree using reference equality checks. This prevents SwipeItems from losing their binding context when content changes, ensuring RelativeSource bindings and commands continue to function correctly.
Issues Fixed
Fixes #32332
Tested the behaviour in the following platforms
Output Screenshot
32332-BeforeFix.mov
32332-AfterFix.mov