-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
base: main
Are you sure you want to change the base?
Conversation
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. |
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
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 forCarouselView
- 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>
/azp run MAUI-UITests-public |
Azure Pipelines successfully started running 1 pipeline(s). |
|
||
[Test] | ||
[Category(UITestCategories.CarouselView)] | ||
public void CarouselShouldWorkProperOnBinding() |
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.
Can update the sample to include a Label with a binding to the CarouselView position and verify it here in the test?
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.
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.
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.
The test is failing on Windows:
Assert.That(rect.X, Is.GreaterThan(0))
Expected: greater than 0
But was: -455
Could you review it?
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.
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.
/azp run MAUI-UITests-public |
Azure Pipelines successfully started running 1 pipeline(s). |
|
||
[Test] | ||
[Category(UITestCategories.CarouselView)] | ||
public void CarouselShouldWorkProperOnBinding() |
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.
The test is failing on Windows:
Assert.That(rect.X, Is.GreaterThan(0))
Expected: greater than 0
But was: -455
Could you review it?
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
Output Screenshot
After.mp4
PositionFix.mp4