Repository navigation
[net11] [Windows] Fix CollectionView ScrollTo MakeVisible behavior - #38117
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 38117Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 38117" |
|
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. |
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
|
/azp run maui-pr-uitests , maui-pr-devicetests |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
This comment has been minimized.
This comment has been minimized.
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🟡 Changes recommended
The handler change would be clearer with an explicit MakeVisible case, and the new screenshot test should use a retry window to reduce bring-into-view timing flakiness.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR fixes Windows CollectionView.ScrollTo(..., ScrollToPosition.MakeVisible) behavior in the Items2 Windows handler so that “MakeVisible” no longer forces top alignment and instead scrolls only as much as needed to reveal the target item. It also adds a HostApp repro page and a UI test to guard against regressions.
Changes:
- Update the Windows Items2 handler to use
double.NaNalignment for “MakeVisible” bring-into-view. - Add a HostApp issue page reproducing the incorrect “MakeVisible scrolls to top” behavior.
- Add a UI test that triggers the scenario and validates via screenshot.
File summaries
| File | Description |
|---|---|
| src/Controls/src/Core/Handlers/Items2/ItemsViewHandler2.Windows.cs | Changes bring-into-view alignment initialization so MakeVisible does not behave like Start. |
| src/Controls/tests/TestCases.HostApp/Issues/Issue38057.cs | Adds a minimal repro page with a button that calls ScrollTo(..., MakeVisible, animate:false). |
| src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue38057.cs | Adds an Appium UI test that exercises the repro and verifies the resulting viewport via screenshot. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 2
- Review effort level: Lite
| double offset = double.NaN; | ||
| switch (args.ScrollToPosition) | ||
| { |
| App.WaitForElement("ScrollToProboscisMonkeyButton"); | ||
| App.Tap("ScrollToProboscisMonkeyButton"); | ||
| VerifyScreenshot(); | ||
| } |
MauiBot
left a comment
There was a problem hiding this comment.
AI Review Summary
@Shalini-Ashokan — new AI review results are available based on commit
ad3fdf3.
🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After Fix
Gate Result: ❌ FAILED
Platform: WINDOWS · Base: net11.0 · Merge base: ad758a9c
🩺 Fix does not pass the tests — every test still fails after applying the fix. The PR's change does not resolve the failure(s).
| Test | Without Fix (expect FAIL) | With Fix (expect PASS) |
|---|---|---|
🖥️ Issue38057 Issue38057 |
✅ FAIL — 534s | ❌ FAIL — 823s |
🔴 Without fix — 🖥️ Issue38057: FAIL ✅ · 534s
Error-relevant lines (filtered from the build log):
at VisualTestUtils.VisualRegressionTester.Fail(String message) in /_/src/TestUtils/src/VisualTestUtils/VisualRegressionTester.cs:line 162
at VisualTestUtils.VisualRegressionTester.VerifyMatchesSnapshot(String name, ImageSnapshot actualImage, String environmentName, ITestContext testContext) in /_/src/TestUtils/src/VisualTestUtils/VisualRegressionTester.cs:line 84
at Microsoft.Maui.TestCases.Tests.UITest.<VerifyScreenshot>g__Verify|13_0(String name, <>c__DisplayClass13_0&) in /_/src/Controls/tests/TestCases.Shared.Tests/UITest.cs:line 485
at Microsoft.Maui.TestCases.Tests.UITest.VerifyScreenshot(String name, Nullable`1 retryDelay, Nullable`1 retryTimeout, Int32 cropLeft, Int32 cropRight, Int32 cropTop, Int32 cropBottom, Double tolerance, Boolean includeTitleBar) in /_/src/Controls/tests/TestCases.Shared.Tests/UITest.cs:line 309
at Microsoft.Maui.TestCases.Tests.Issues.Issue38057.Issue38057_MakeVisiblePositionsTargetAtBottomOfViewport() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue38057.cs:line 21
at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
🟢 With fix — 🖥️ Issue38057: FAIL ❌ · 823s
Error-relevant lines (filtered from the build log):
at VisualTestUtils.VisualRegressionTester.Fail(String message) in /_/src/TestUtils/src/VisualTestUtils/VisualRegressionTester.cs:line 162
at VisualTestUtils.VisualRegressionTester.VerifyMatchesSnapshot(String name, ImageSnapshot actualImage, String environmentName, ITestContext testContext) in /_/src/TestUtils/src/VisualTestUtils/VisualRegressionTester.cs:line 84
at Microsoft.Maui.TestCases.Tests.UITest.<VerifyScreenshot>g__Verify|13_0(String name, <>c__DisplayClass13_0&) in /_/src/Controls/tests/TestCases.Shared.Tests/UITest.cs:line 485
at Microsoft.Maui.TestCases.Tests.UITest.VerifyScreenshot(String name, Nullable`1 retryDelay, Nullable`1 retryTimeout, Int32 cropLeft, Int32 cropRight, Int32 cropTop, Int32 cropBottom, Double tolerance, Boolean includeTitleBar) in /_/src/Controls/tests/TestCases.Shared.Tests/UITest.cs:line 309
at Microsoft.Maui.TestCases.Tests.Issues.Issue38057.Issue38057_MakeVisiblePositionsTargetAtBottomOfViewport() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue38057.cs:line 21
at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
⚠️ Failure Details
- ❌ Issue38057 FAILED with fix (should pass)
Issue38057_MakeVisiblePositionsTargetAtBottomOfViewport [3 s]VisualTestUtils.VisualTestFailedException : Baseline snapshot not yet created: D:\a\1\s\artifacts\bin\Controls.TestCases.WinUI.Tests\Debug\net11.0\snapshots\windows\Issue38057_MakeVisiblePositionsTa...
📁 Fix files reverted (1 files)
src/Controls/src/Core/Handlers/Items2/ItemsViewHandler2.Windows.cs
📋 Pre-Flight — Context & Validation
PR #38117 Pre-Flight
Context
- PR:
[net11] [Windows] Fix CollectionView ScrollTo MakeVisible behavior - Base/head:
net11.0/Shalini-Ashokan:fix-38057 - Issue: #38057, a Windows regression introduced with .NET 11 Preview 6.
CollectionView.ScrollTo(..., ScrollToPosition.MakeVisible)moves the requested item to the top instead of scrolling only enough to reveal it at the bottom of the viewport. - Affected scenarios reported by the issue: scrolling by index or object, with grouped and non-grouped data.
- Gate: FAILED in the prior phase because tests did not behave as expected. Do not rerun gate verification and do not create or overwrite
gate/content.md.
Submitted PR Change
The production diff changes one line in:
src/Controls/src/Core/Handlers/Items2/ItemsViewHandler2.Windows.cs
- double offset = AlignToStart;
+ double offset = double.NaN;Start, Center, and End still replace the default with 0.0, 0.5, and 1.0. MakeVisible falls through and passes the default to both VerticalAlignmentRatio and HorizontalAlignmentRatio in BringIntoViewOptions.
The PR also adds:
src/Controls/tests/TestCases.HostApp/Issues/Issue38057.cssrc/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue38057.cs
The UI test taps ScrollToProboscisMonkeyButton and verifies a screenshot after requesting the off-screen Proboscis Monkey with MakeVisible.
Active Windows Path
Despite older repository guidance saying Items2 has no Windows implementation, this checkout contains the new Windows CV2 handler from #34600. AppHostBuilderExtensions.AddControlsHandlers registers CollectionViewHandler2 on Windows when RuntimeFeature.IsWindowsCollectionView2HandlerEnabled; otherwise it registers the legacy handler. The changed ItemsViewHandler2.Windows.cs path is therefore active for the reported CV2 scenario.
The original CV2 implementation always initialized offset to AlignToStart, so an unhandled MakeVisible request was sent to WinUI as explicit top/left alignment. The submitted fix changes this to WinUI's double.NaN unconstrained-alignment sentinel.
Candidate Constraints
- Each candidate must use a mechanism different from the submitted
double.NaNdefault and different from earlier candidate attempts. - The only production target permitted for investigation/modification is
src/Controls/src/Core/Handlers/Items2/ItemsViewHandler2.Windows.cs, subject to the allow-list generated byEstablishBrokenBaseline.ps1. - Preserve explicit
Start,Center, andEndbehavior, both orientations, grouped/index/item lookup behavior, animation behavior, and unloaded-view deferral. - Follow the Windows CV2 runtime registration found in the code rather than the stale handler-detection instruction.
- The working tree contains a large pre-existing trusted-review infrastructure overlay. Do not clean, reset, restore, commit, or otherwise alter those unrelated changes. If the mandatory baseline script rejects the dirty tree, record the candidate as
Blocked, run the exact restore command required by the skill, and continue.
Allowed Test
Primary test only:
pwsh .github/scripts/BuildAndRunHostApp.ps1 -Platform windows -TestFilter "Issue38057_MakeVisiblePositionsTargetAtBottomOfViewport"No additional mandatory regression-test section was supplied in the STEP 5a prompt, so no other tests may be run. Each candidate gets one implementation/test pass and at most one focused correction/retest.
🔬 Code Review — Deep Analysis
Code Review — PR #38117
Independent Assessment
What this changes: The Windows CollectionView2 handler now passes WinUI's unconstrained-alignment sentinel (double.NaN) for ScrollToPosition.MakeVisible; explicit Start, Center, and End requests still use alignment ratios 0.0, 0.5, and 1.0. The PR also adds a Windows host page and screenshot UI test for a non-grouped, item-based, non-animated request.
Inferred motivation: MakeVisible previously inherited the Start ratio and therefore forced an off-screen target to the top/left instead of allowing WinUI to move only enough to reveal it.
Approach assessment: The one-line handler change is localized and matches WinUI's BringIntoViewOptions convention. It preserves item lookup, grouping, orientation, animation, and unloaded-view deferral. The single expert-review pass reported no actionable file:line findings, so inline-findings.json is [].
Reconciliation with PR Narrative
Author claims: The Windows CollectionView2 handler incorrectly initialized MakeVisible with top alignment and should instead use double.NaN so WinUI performs minimal scrolling.
Agreement/disagreement: The claim matches the submitted diff and active runtime path. AppHostBuilderExtensions.AddControlsHandlers registers CollectionViewHandler2 on Windows when the Windows CollectionView2 feature switch is enabled, despite stale repository guidance claiming that Items2 has no Windows implementation.
Prior Review Reconciliation
No prior ❌ Error findings were found across the top-level review, inline-review-comment, and PR issue-comment surfaces.
Blast Radius Assessment
- Runs for all instances: The method handles all Windows CollectionView2 scroll requests, but the changed default affects only
MakeVisible; explicit positions overwrite it. - Startup impact: None. The behavior executes only in response to
ScrollToRequested. - Static/shared state: None.
- Default/null behavior: No new nullable state is introduced; the existing platform-view and index guards remain unchanged.
CI Status
- Required-check result: Undetermined because
gh pr checks --requiredwas unavailable without authentication. - Trusted Gate result: ❌ FAILED because both runs reached
VerifyScreenshotwithout an existing Windows baseline snapshot. This does not establish a behavioral failure of the production fix, but it means the test did not prove the expected fail-without-fix/pass-with-fix transition. - Classification: Validation gap, not a confirmed production-code regression.
- Action taken: Confidence capped at low; Gate verification was not rerun.
Findings
No actionable code findings.
Failure-Mode Probing
- Already-visible target: Both alignment ratios remain unconstrained, so WinUI can avoid forcing the item to an edge.
- Target before or after the viewport: WinUI selects the minimum bring-into-view movement rather than always applying start alignment.
- Horizontal layout: The same unconstrained sentinel is supplied to the horizontal ratio; explicit alignment behavior is unchanged for both axes.
- Grouped/index/item lookup: All lookup branches execute before alignment selection and are untouched by this change.
- Handler disconnect/reconnect and unloaded deferral: No subscriptions, latches, or shared state were added. Existing lifecycle behavior is unchanged.
- Adjacent coverage: The submitted UI test exercises only a vertical, non-grouped, item-based, non-animated below-viewport target. Grouped, position-based, horizontal, already-visible, above-viewport, and animated cases remain unverified by this test.
External Output Contract
Not applicable.
Verdict: NEEDS_DISCUSSION
Confidence: low
Summary: The production fix is narrowly scoped and technically sound, and the expert reviewer found no blocking or discussion-level code issue. The trusted Gate cannot permit approval because the new visual test lacked a baseline and therefore failed with and without the fix; the behavioral correction remains unproven by the submitted regression test.
🛠️ Try-Fix — Analysis & Comparison
PR #38117 Try-Fix Aggregate
Candidate 1 - gpt-5.3-codex
Result: Blocked
Approach: Baseline-gated no-code attempt. The candidate reviewed the submitted double.NaN default-alignment change but could not open a safe implementation window.
Prior approach avoided: The submitted PR changes ScrollToRequested's initial alignment from AlignToStart to double.NaN, causing MakeVisible to pass unconstrained alignment ratios to WinUI.
Mechanism-level difference: No alternative runtime mechanism was applied. EstablishBrokenBaseline.ps1 rejected the large pre-existing dirty working tree before it could generate a RevertedFiles allow-list, so the skill contract prohibited all tracked code edits.
Production files changed: None.
Diff: Empty.
Tests: Not run. The intended and only permitted test was:
pwsh .github/scripts/BuildAndRunHostApp.ps1 -Platform windows -TestFilter "Issue38057_MakeVisiblePositionsTargetAtBottomOfViewport"Failure analysis: The baseline script reported ERROR: DIRTY WORKING DIRECTORY - Cannot establish baseline. The candidate correctly made no production change and did not run the test without a restorable baseline.
Self-review: 0 findings.
Restore: The required pwsh .github/scripts/EstablishBrokenBaseline.ps1 -Restore command ran and reported No baseline state found; no baseline state had been created and no attempt edits were made.
Full report: ../try-fix-1/content.md
Aggregate Status After Candidate 1
- Completed candidates: 1 of at most 2
- Passing candidates: 0
- Failed candidates: 0
- Blocked candidates: 1
Candidate 2 - gpt-5.6-sol
Result: Blocked
Approach: Direction-aware edge alignment for MakeVisible. The intended implementation would inspect the orientation-neutral visible index range after load, skip scrolling when the target is already visible, explicitly align a later target to End, and explicitly align an earlier target to Start.
Earlier result accounted for: Candidate 1 made no production change because baseline establishment failed. Candidate 2 did not treat that repeated baseline no-op as a new mechanism and did not reopen or rerun candidate 1.
Prior approaches avoided: Unlike the submitted PR, this design would never send double.NaN alignment ratios or delegate edge selection to WinUI's unconstrained-alignment sentinel. Unlike candidate 1, it records a concrete alternative runtime mechanism even though the same environment blocker prevented implementation.
Mechanism-level difference: The target's relationship to the realized visible range would choose the behavior directly: already visible means no operation, below/after the viewport means explicit end alignment, and above/before the viewport means explicit start alignment. This would place the reported below-viewport item at the bottom through direction-aware edge selection rather than WinUI's NaN interpretation.
Production files changed: None. Baseline failure prevented creation of a RevertedFiles allow-list.
Diff: Empty.
Tests: Not run. The only permitted command remained:
pwsh .github/scripts/BuildAndRunHostApp.ps1 -Platform windows -TestFilter "Issue38057_MakeVisiblePositionsTargetAtBottomOfViewport"test-output.log records TEST NOT RUN; no other test or gate was executed.
Failure analysis: EstablishBrokenBaseline.ps1 rejected the same 66-file pre-existing trusted-review overlay with ERROR: DIRTY WORKING DIRECTORY - Cannot establish baseline. Because .github/.baseline-state.json was not created, the skill contract prohibited tracked edits. The candidate therefore has no empirical result for the direction-aware design.
Self-review: 0 findings; there was no candidate code diff.
Restore: The required pwsh .github/scripts/EstablishBrokenBaseline.ps1 -Restore command ran and reported No baseline state found; this was the expected no-state result because no attempt edit occurred.
Full report: ../try-fix-2/content.md
Final Aggregate Status
- Completed candidates: 2 of 2
- Passing candidates: 0
- Failed candidates: 0
- Blocked candidates: 2
- Implemented candidate diffs: 0
- Primary test executions: 0
Both bounded attempts were prevented from reaching implementation by the mandatory baseline safety gate. Candidate 2 records a distinct direction-aware alternative for STEP 5b comparison, but it must not be represented as validated or as a usable patch.
🏁 Report — Final Recommendation
⚠️ Final Recommendation: REQUEST CHANGES
Winner: pr
The submitted production fix is the strongest available implementation: it is localized, uses WinUI's established unconstrained-alignment sentinel for MakeVisible, preserves explicit Start/Center/End behavior, and received no actionable findings from the one expert-review pass. Approval is not available because the trusted Gate failed: the new screenshot test had no Windows baseline and therefore failed both without and with the fix instead of proving the required fail/pass transition.
Comparative Ranking
| Rank | Candidate | Implementation | Validation | Assessment |
|---|---|---|---|---|
| 1 | pr |
Submitted double.NaN default for MakeVisible, plus host-app and UI-test files |
Gate ❌ failed because the snapshot baseline was absent | Best concrete implementation and expert-clean, but not approvable until its regression test is made executable and proves the fix |
| 2 | pr-plus-reviewer |
Code-identical to pr; expert review supplied no changes |
No targeted rerun; git diff --check passed and the same failed Gate applies |
Tied technically with pr, but has no substantive refinement or validation advantage, so the raw submitted candidate wins the tie |
| 3 | try-fix-2 |
Proposed direction-aware no-op/Start/End selection, but no code diff exists | Blocked before testing | A distinct idea, but it is neither implemented nor empirically validated; it cannot outrank a concrete reviewed fix |
| 4 | try-fix-1 |
No alternative runtime mechanism and no code diff | Blocked before testing | Baseline-gated no-op with no usable candidate |
No candidate passed the regression test. The raw PR is the only submitted, reviewable production solution; pr-plus-reviewer is identical, while both STEP 5a candidates were blocked before implementation and testing. The rule preferring passing candidates therefore cannot elevate any alternative.
Expert Review
inline-findings.json:[]- Production finding: no blocking or discussion-level code defect identified.
- Blast radius: Windows CollectionView2
ScrollToRequested; onlyMakeVisiblechanges because explicit positions overwrite the default ratio. - Adjacent scenarios not covered by the submitted test: grouped and index-based requests, horizontal layouts, already-visible and above-viewport targets, and animated scrolling.
Required Change Before Approval
Add the required Windows visual baseline or replace the screenshot-only check with an existing deterministic assertion pattern that can distinguish the target's viewport position. The resulting trusted Gate must demonstrate failure without the fix and success with the submitted PR fix.
📱 UI Tests — CollectionView
Detected UI test categories: CollectionView
[!WARNING]
No UI test results were produced for the detected categories. The platform-pool run
returned no results — most often because the PR build failed (see the Gate section) or
the deep UI test stage was skipped. Fix the build/gate issues and push again; the review
re-runs on new commits (a maintainer can also re-run it).
🧭 Next Steps — review latest findings
No alternative fix was selected for this run. Review the session findings and CI results before merging.
|
/azp run maui-pr |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/azp run maui-pr-uitests, maui-pr-devicetests |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
kubaflo
left a comment
There was a problem hiding this comment.
Could you please commit snapshot and check if other failing tests are related?
@kubaflo, I have committed the baseline snapshots. The test failures are unrelated to my fix. |
There was a problem hiding this comment.
🟢 Approval recommended
The change is small, targeted, and accompanied by an automated UI test; the only remaining feedback is a minor maintainability suggestion.
Review details
Suppressed comments (1)
src/Controls/src/Core/Handlers/Items2/ItemsViewHandler2.Windows.cs:1726
- The MakeVisible behavior is now implemented implicitly by leaving
offsetasdouble.NaN. Adding an explicitScrollToPosition.MakeVisible(and adefault) makes the intent clearer and prevents future refactors from accidentally reintroducing Start-alignment for MakeVisible.
double offset = double.NaN;
switch (args.ScrollToPosition)
{
case ScrollToPosition.Start:
offset = AlignToStart;
break;
case ScrollToPosition.Center:
offset = AlignToCenter;
break;
case ScrollToPosition.End:
offset = AlignToEnd;
break;
}
- Files reviewed: 3/9 changed files
- Comments generated: 0 new
- Review effort level: Lite
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
On Windows, CollectionView.ScrollTo(..., ScrollToPosition.MakeVisible) incorrectly positions the target item at the top of the CollectionView instead of scrolling only as much as necessary to make the item visible.
Root Cause
The CV2 Windows handler initializes MakeVisible with alignment 0.0, which WinUI interprets as top alignment.
Because there is no explicit MakeVisible case, it behaves like Start and moves the target item to the top.
Description of Change
Initialize the alignment with double.NaN, which tells WinUI not to force a specific position.
WinUI then scrolls only enough to reveal the item, matching the expected behavior and the older CV1 handler.
Validated the behavior in the following platforms
Issues Fixed
Fixes #38057
Output ScreenShot
644350959-1d5d38d5-dbcb-4dc9-90e8-bb0a469bb1da.mp4
I9-Scrollby-object-for-scrollto-windows.mov