-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fix CarouselView ItemTemplate Runtime Updates #29546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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. |
There was a problem hiding this 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 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
/azp run MAUI-UITests-public |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run MAUI-UITests-public |
Azure Pipelines successfully started running 1 pipeline(s). |
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