Fix CarouselView ItemTemplate Runtime Updates #29546
Merged
PureWeen merged 5 commits intodotnet:inflight/currentfrom May 21, 2025
Merged
Fix CarouselView ItemTemplate Runtime Updates #29546PureWeen merged 5 commits intodotnet:inflight/currentfrom
PureWeen merged 5 commits intodotnet:inflight/currentfrom
Conversation
Contributor
|
Hey there @@Shalini-Ashokan! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an issue where CarouselView's ItemTemplate was not updating at runtime by calling UpdateItemsSource() in the Windows handler.
- Fixed the dynamic update behavior in CarouselView by ensuring the correct template is applied.
- Added automated tests in both TestCases.Shared.Tests and TestCases.HostApp to validate the change.
- Updated the Windows handler to call UpdateItemsSource() after setting ListViewBase.ItemTemplate.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29462.cs | New automated test for dynamic ItemTemplate change |
| src/Controls/tests/TestCases.HostApp/Issues/Issue29462.cs | New host app UI and test trigger for changing ItemTemplate |
| src/Controls/src/Core/Handlers/Items/CarouselViewHandler.Windows.cs | Updated UpdateItemTemplate() to call UpdateItemsSource() to apply custom templates |
Comments suppressed due to low confidence (1)
src/Controls/tests/TestCases.HostApp/Issues/Issue29462.cs:56
- The variable name 'itemTempateButton' appears to be misspelled. It would be clearer if it were renamed to 'itemTemplateButton'.
var itemTempateButton = new Button
Contributor
|
/azp run MAUI-UITests-public |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Contributor
|
/azp run MAUI-UITests-public |
|
Azure Pipelines successfully started running 1 pipeline(s). |
rmarinho
approved these changes
May 20, 2025
2aea9c9 to
103ec77
Compare
github-actions bot
pushed a commit
that referenced
this pull request
May 22, 2025
* Fixed the item template dynamic changes * Added a test case * Added test case and added snapshots * committed the image * committed the image
github-actions bot
pushed a commit
that referenced
this pull request
May 30, 2025
* Fixed the item template dynamic changes * Added a test case * Added test case and added snapshots * committed the image * committed the image
github-actions bot
pushed a commit
that referenced
this pull request
May 30, 2025
* Fixed the item template dynamic changes * Added a test case * Added test case and added snapshots * committed the image * committed the image
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!
Issue Details
In CarouselView, the ItemTemplate property cannot be changed dynamically at runtime.
Root Cause
The UpdateItemTemplate() method always sets ListViewBase.ItemTemplate to the default CarouselItemsViewTemplate, regardless of whether a custom item template has been defined.
Description of Change
The fix calls UpdateItemsSource() method to recreating the items through TemplatedItemSourceFactory, allowing the correct template to be applied.
Reference
I resolved the issue by referring to the following code.
maui/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.Windows.cs
Line 277 in acd2a94
Validated the behavior in the following platforms
Issues Fixed
Fixes #29462
Output ScreenShot
Before29462.mp4
After29462.mp4