Skip to content

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Shalini-Ashokan
Copy link
Contributor

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.

Validated the behavior in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Issues Fixed

Fixes #29462

Output ScreenShot

Before After
Before29462.mp4
After29462.mp4

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label May 16, 2025
Copy link
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.

@dotnet-policy-service dotnet-policy-service bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label May 16, 2025
@Shalini-Ashokan Shalini-Ashokan marked this pull request as ready for review May 16, 2025 13:20
@Copilot Copilot AI review requested due to automatic review settings May 16, 2025 13:20
@Shalini-Ashokan Shalini-Ashokan requested a review from a team as a code owner May 16, 2025 13:20
Copy link
Contributor

@Copilot 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 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

@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Windows] CarouselView ItemTemplate Not Updating at Runtime
3 participants