Skip to content

Fix for CarouselView Position property not working properly in windows platfrom #29591

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 9 commits into
base: main
Choose a base branch
from

Conversation

SuthiYuvaraj
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 position is updated programmatically , position is not updated properly , as it scrolls back to the previous position.

RootCause of the Issue:

The issue arises because the position update triggers an automatic scroll due to the MapPosition change. During this scroll, the center index is recalculated, which inadvertently updates the CarouselView's position again via the Scrolled event — potentially overriding the intended position with an intermediate state.

Description of Change

To address this, I modified the handling logic to ensure that HandleScroll is only triggered once the scroll is fully completed and not during intermediate states. This prevents premature updates to the position based on transient center index values, preserving the intended programmatic navigation behavior.

Issues Fixed

Fixes #15443

Tested the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Output Screenshot

Before Issue Fix After Issue Fix
After.mp4
PositionFix.mp4

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label May 20, 2025
Copy link
Contributor

Hey there @@SuthiYuvaraj! 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 20, 2025
@sheiksyedm sheiksyedm added platform/windows area-controls-collectionview CollectionView, CarouselView, IndicatorView labels May 20, 2025
@SuthiYuvaraj SuthiYuvaraj marked this pull request as ready for review May 20, 2025 13:15
@Copilot Copilot AI review requested due to automatic review settings May 20, 2025 13:15
@SuthiYuvaraj SuthiYuvaraj requested a review from a team as a code owner May 20, 2025 13:15
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

Fixes the issue where programmatic updates to CarouselView.Position on Windows get overwritten by intermediate scroll events by deferring the scroll handling until the final event.

  • Adds a check in ScrollViewChanged to ignore intermediate scroll events for CarouselView
  • Introduces a HostApp sample and a UI test to verify correct programmatic navigation

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/Controls/src/Core/Handlers/Items/ItemsViewHandler.Windows.cs Updated ScrollViewChanged to skip intermediate scroll events for CarouselView
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue15443.cs Added UI test that asserts carousel items are positioned correctly after commands
src/Controls/tests/TestCases.HostApp/Issues/Issue15443.cs Added sample page and ViewModel demonstrating programmatic position setting
Comments suppressed due to low confidence (1)

src/Controls/src/Core/Handlers/Items/ItemsViewHandler.Windows.cs:444

  • [nitpick] Consider simplifying the nested if logic by using an early return. For example:
void ScrollViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
{
    if (Element is CarouselView && e.IsIntermediate)
        return;
    HandleScroll(_scrollViewer);
}
```This reduces nesting and makes the intent clearer.

void ScrollViewChanged(object sender, ScrollViewerViewChangedEventArgs e)

</details>

@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).


[Test]
[Category(UITestCategories.CarouselView)]
public void CarouselShouldWorkProperOnBinding()
Copy link
Contributor

Choose a reason for hiding this comment

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

Can update the sample to include a Label with a binding to the CarouselView position and verify it here in the test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @jsuarezruiz , I have updated the sample to include a Label that's bound to the CarouselView Position property. The label updates dynamically as the carousel position changes. I have also added verification in the test to ensure that the label reflects the correct position during navigation.

Copy link
Contributor

Choose a reason for hiding this comment

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

The test is failing on Windows:

Assert.That(rect.X, Is.GreaterThan(0))
Expected: greater than 0
But was:  -455

Could you review it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @jsuarezruiz , The test is currently failing on Windows, although it runs fine locally. Upon analysis, the failure occurs before navigating to the third item. Given this, we would like to re-trigger the CI to verify if the issue persists.

@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).


[Test]
[Category(UITestCategories.CarouselView)]
public void CarouselShouldWorkProperOnBinding()
Copy link
Contributor

Choose a reason for hiding this comment

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

The test is failing on Windows:

Assert.That(rect.X, Is.GreaterThan(0))
Expected: greater than 0
But was:  -455

Could you review it?

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 community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/windows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Windows][CarouselView] Position property not working properly
3 participants