Skip to content

[Windows] Fix doubled CollectionView item spacing - #38960

Merged
kubaflo merged 4 commits into
inflight/currentfrom
jfversluis-issue-38959-reproduction
Sep 28, 2026
Merged

kubaflo merged 4 commits into
inflight/currentfrom
jfversluis-issue-38959-reproduction

Conversation

@jfversluis

@jfversluis jfversluis commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

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!

Description of Change

Windows CollectionView applied the full requested spacing to both sides of each item container. Adjacent margins/paddings add, so ItemSpacing="30" produced a 60-DIP gap, not 30.

Split the requested spacing evenly between the two contributing sides in StructuredItemsViewHandler.Windows.cs:

  • Vertical linear layouts: top/bottom margins.
  • Horizontal linear layouts: left/right padding.
  • Grid layouts: horizontal/vertical margins.

For any finite spacing S, the adjacent contributions become S/2 + S/2 = S. This is not a DPI correction: WinUI handles scaling of these logical units. Default zero spacing, the existing symmetric edge-spacing approach, and native style inheritance are retained. Applications compensating for the doubled spacing will need to remove that workaround. This changes the default Windows CollectionView handler, not the opt-in obsolete compatibility renderer.

Empirical before/after evidence

The issue's XAML scenario was reproduced in the Sandbox against repository sources on Windows ARM64. These are actual WinUI-rendered page captures, not mockups. Native item bounds were measured after layout.

Before: requested 30, measured 60 DIPs After: requested 30, measured 30 DIPs
Before: CollectionView spacing is doubled After: CollectionView spacing matches the requested value

Item dimensions stayed 300 × 40 DIPs. Before, item Y positions were 30, 130, 230, 330, 430, 530, 630; after, 15, 85, 155, 225, 295, 365, 435. All six adjacent gaps changed from 60 to 30 DIPs.

Additional runtime sampling completed 20 captures with zero geometry-check failures, including both linear orientations, both grid orientations, and changing spacing back to zero:

Requested linear spacing Measured vertical gap Measured horizontal gap
0 0 0
10 10 10
30 30 30
7.5 8 8
0 after updates 0 0

All captures recorded XamlRoot.RasterizationScale = 1.0 and layout rounding enabled. The fractional result is 8, not exactly 7.5, due to pixel snapping. No other display scale was empirically tested, and no OS scaling settings were changed.

Grid native-container gaps measured 30/10 for requested horizontal/vertical spacing 30/10, in both orientations. Fixed-size content centered inside a larger grid cell can have additional whitespace; that is distinct from inter-container spacing.

Regression coverage and verification

Windows device tests cover rendered linear gaps at zero, fractional, and nonzero spacing; both grid axes/orientations; live spacing changes; and untemplated style mapping. The tests measure the current realized native view wrappers, reacquiring them when a style update replaces item templates.

The repository's full A/B verification runner completed with VERIFICATION PASSED:

  • Original framework code: 10 failed, 0 passed targeted cases.
  • Fixed framework code: 10 passed, 0 failed targeted cases.

The fix and tests were reviewed independently with GPT-5.3-Codex and GPT-5.6 Sol. Feedback was addressed, and final reviews reported no remaining actionable findings. The subsequent independent Windows review on head 2e987fc48c also reproduced 10 failures without the fix and 10 passes with it, with no actionable code-review findings. That review's own UI stage produced no results; screenshot verification below comes from the separate public UI pipeline.

Windows UI baseline updates

The initial UI build 1614797 exposed eight snapshots that encoded the old doubled spacing. Only those eight Windows baselines were updated from inspected CI captures. Item sizes, selection indicators, and closed swipe states are preserved; the changed gutters and resulting content positions reflect the corrected spacing. For example, CVHorizontalLinearItemsLayoutItemSpacing retains identical item widths while all five measured gaps change from 20 to the requested 10 pixels.

Device build 1614798, on the preceding code-identical head 5ee75080b0, passed all ten new Windows regression cases. Its packaged and unpackaged Windows CollectionView result files each report 50 passed, 0 failed, 1 known skip. After the snapshot updates, a fresh local device run also passed all ten targeted cases (full CollectionView results: 50 passed, 0 failed, 1 skipped). The current-head device build 1614911 confirmed those same packaged and unpackaged Windows results, including all ten new regression cases.

Local Appium screenshot verification was blocked by WinAppDriver's /status returning HTTP 500, so none of the eight UI methods ran locally. All eight updated screenshot tests passed in UI build 1614910, verified from their actual per-test results: CVHorizontalLinearItemsLayoutItemSpacing, CollectionViewHeightIsCorrectAfterDelayedLoad, CollectionViewPreSelectionShouldUpdate, CollectionViewSelectionModeOnLightTheme, Issue23377ItemSpacing, OnlyManuallySwipedItemShouldBeOpened, VerifyCVBackgroundAndBackgroundColorWithVSM, and VerticalItemsRemainFullyVisibleAfterChangingSpacing. These are CI screenshot passes, not an inference from the device tests.

Build artifacts and CI scope

Main build 1614908 completed successfully. Its PackageArtifacts archive contains Microsoft.Maui.Controls and Microsoft.Maui.Controls.Core version 10.0.120-ci.pr38960.26478.60, including the Windows framework assemblies. Follow Testing PR Builds to try these packages.

The broader device and UI pipelines are not all green. Their non-Windows failures and timed-out retries are tracked separately from the verified Windows spacing results; the targeted passes above do not imply whole-suite success.

Related work

After developing this fix independently, I checked for existing fixes. #38367 addresses a different untemplated-grid stretching issue in the .NET 11 handler; it does not correct these additive margins/paddings in the current Windows handler.

Issues Fixed

Fixes #38959

jfversluis and others added 3 commits September 28, 2026 16:48
Split linear and grid spacing across adjacent item containers and cover rendered gaps, runtime updates, fractional values, and untemplated items.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Avoid inner TextBlock metrics, context-driven handler replacement, and stale templates after spacing changes. Report measured gaps on failure.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 28, 2026 15:55
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 38960

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 38960"

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

@jfversluis

Copy link
Copy Markdown
Member Author

/azp run maui-pr-devicetests

@jfversluis

Copy link
Copy Markdown
Member Author

/azp run maui-pr-uitests

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

1 similar comment
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Windows rendering behavior requires final human validation.

Review effort: Lite
Findings: None

What changed in this PR

Fixes doubled Windows CollectionView spacing by splitting spacing across adjacent item-container sides.

Changes:

  • Applies half-spacing to linear and grid layouts.
  • Adds Windows regression tests for orientations, grids, fractional values, and live updates.
File Description
src/​Controls/​tests/​DeviceTests/​Elements/​CollectionView/​CollectionViewTests.Windows.cs Adds rendered-spacing regression coverage.
src/​Controls/​src/​Core/​Handlers/​Items/​StructuredItemsViewHandler.Windows.cs Applies half-spacing margins and padding.

Refresh only the eight baselines whose rendered gaps changed with the spacing fix. Preserve selection, sizing, and swipe behavior.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 28, 2026 17:23
@jfversluis

Copy link
Copy Markdown
Member Author

/azp run maui-pr-uitests

@jfversluis

Copy link
Copy Markdown
Member Author

/azp run maui-pr-devicetests

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

1 similar comment
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

The compatibility renderer remains uncorrected, and the claimed Windows baseline updates are absent from the supplied change set.

Review effort: Lite
Findings: None

@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Sep 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Note

🔍 /review started

AzDO build 15488726 is running for windows.

The s/agent-review-in-progress label stays on this PR while the run is active. The final recommendation and outcome labels are posted only after Gate, expert review, and Deep UI tests finish.

@jfversluis

Copy link
Copy Markdown
Member Author

Clarification for the latest review overview: the eight Windows PNG baseline updates are included in commit 2e987fc and are present in this PR's Files changed. They are binary files, so a text-only diff can omit their contents.

The runtime fix targets the default Windows CollectionViewHandler, registered in AddControlsHandlers. The separate obsolete Compatibility.Platform.UWP.StructuredItemsViewRenderer is unchanged; this PR does not claim to fix or validate that opt-in legacy renderer.

The current-head UI rerun is build 1614910. Its result is still pending; the PR description explicitly records the local WinAppDriver blocker rather than claiming local screenshot tests passed.

@kubaflo

This comment has been minimized.

@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Sep 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Note

🔍 /review started

AzDO build 15493403 is running for windows.

The s/agent-review-in-progress label stays on this PR while the run is active. The final recommendation and outcome labels are posted only after Gate, expert review, and Deep UI tests finish.

@github-actions

Copy link
Copy Markdown
Contributor

The /review tests workflow failed before publishing a report. View the workflow run.

This is an automation failure, not a verdict on the PR tests. Maintainers can retry /review tests after the workflow failure is resolved.

@kubaflo
kubaflo changed the base branch from main to inflight/current September 28, 2026 22:15
@kubaflo
kubaflo merged commit 6592513 into inflight/current Sep 28, 2026
180 of 199 checks passed
@kubaflo
kubaflo deleted the jfversluis-issue-38959-reproduction branch September 28, 2026 22:15
@github-actions github-actions Bot added this to the .NET 10 SR12 milestone Sep 28, 2026

@MauiBot MauiBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

AI Review Summary

@jfversluis — new AI review results are available based on commit 2e987fc.

Gate No Tests Confidence Low Platform Windows


🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After Fix

Gate Result: ⚠️ SKIPPED

No tests were detected in this PR.

Recommendation: Add tests to verify the fix using the write-tests-agent.


📋 Pre-Flight — Context & Validation

PR #38960 Pre-Flight

Context

  • PR: [Windows] Fix doubled CollectionView item spacing
  • State: Merged into inflight/current as 6592513435ff97c207df1124749650ba20f10424; reviewed head 2e987fc48c76ca4876087e7e25fca8505617e191.
  • Issue: #38959 reports that LinearItemsLayout.ItemSpacing="30" renders substantially larger gaps on Windows than Android in .NET MAUI 10.0.110.
  • Platform: Windows. Handlers/Items/ is the only Windows CollectionView implementation; Items2/ has no Windows path.
  • Gate: Previously skipped with no tests detected. Do not rerun the gate and do not modify gate/content.md.

Existing PR approach

WinUI receives symmetric spacing on both sides of every item container. Adjacent contributions add, so applying the full requested value to both sides doubles the rendered inter-item gap. The PR changes:

  • Grid margins from (h, v, h, v) to (h / 2, v / 2, h / 2, v / 2).
  • Vertical linear margins from (0, v, 0, v) to (0, v / 2, 0, v / 2).
  • Horizontal linear padding from (h, 0, h, 0) to (h / 2, 0, h / 2, 0).

The implementation change is four substitutions in:

src/Controls/src/Core/Handlers/Items/StructuredItemsViewHandler.Windows.cs

The PR also adds 201 lines of Windows device coverage and updates eight Windows UI snapshots. No public API is changed.

Required alternative-fix distinction

Candidates must not repeat the PR's split the requested spacing equally across both symmetric sides mechanism. A different line, helper, or call site that still divides every symmetric contribution by two is the same approach. Each candidate must use a different root-cause hypothesis or spacing mechanism and explain the causal distinction.

Narrow validation surface

Use only the Windows Controls device-test runner and the PR's ten spacing cases:

  • LinearItemSpacingMatchesRenderedGap (6 theory cases)
  • GridItemSpacingMatchesRenderedGap (2 theory cases)
  • UntemplatedLinearItemSpacingIsSharedBetweenAdjacentContainers (2 theory cases)

The tests cover zero, fractional, and nonzero values; vertical and horizontal linear layouts; both grid orientations and axes; live spacing updates; and untemplated style mapping. Do not run a full test suite. The aggregate test command supplied to each attempt must remain scoped to these cases.

Relevant changed files

  • src/Controls/src/Core/Handlers/Items/StructuredItemsViewHandler.Windows.cs
  • src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.Windows.cs
  • Eight Windows CollectionView snapshot PNGs under src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/

Constraints for attempts

  • One implementation/test pass and at most one focused correction/retest.
  • Use EstablishBrokenBaseline.ps1 and its RevertedFiles allow-list exactly as required by the try-fix skill.
  • Perform the skill's expert review inline; do not launch maui-expert-reviewer or any other reviewer.
  • Restore exclusively with pwsh .github/scripts/EstablishBrokenBaseline.ps1 -Restore.
  • Persist the candidate narrative and aggregate before any later candidate begins.

🔬 Code Review — Deep Analysis

Code Review — PR #38960

Independent Assessment

What this changes: The Windows CollectionView handler now applies half of each requested spacing value to each symmetric side of adjacent item containers. Grid layouts use half horizontal and vertical margins, vertical linear layouts use half top/bottom margins, and horizontal linear layouts use half left/right padding. The PR also adds Windows device coverage for linear and grid orientations, zero/fractional/nonzero spacing, live updates, and untemplated style mapping, and updates eight Windows snapshots.

Inferred motivation: WinUI adds the full contributions from adjacent containers, so assigning the requested spacing to both symmetric sides produces a rendered gap twice as large as requested.

Reconciliation with PR Narrative

The submitted implementation matches the stated root cause and correction. The half-side contributions preserve the existing symmetric edge-spacing strategy while making each adjacent pair sum to the requested spacing.

Prior Review Reconciliation

No prior error-level findings were found on the available top-level review, inline review-comment, or PR issue-comment surfaces.

Blast Radius Assessment

  • Runs for all instances: Yes, for Windows CollectionView instances using the only Windows handler in Handlers/Items.
  • Startup impact: None; the changed arithmetic runs while constructing/updating native item-container styles.
  • Static/shared state: No new state was added. Existing cached styles remain, with only their spacing values changed.
  • Public API: None.

CI / Gate Evidence

  • Gate result: Skipped — no tests detected in this PR.
  • Required checks: Could not be queried because GitHub CLI authentication is unavailable.
  • Review consequence: Evidence remains undetermined, so confidence is capped at low and the expert verdict cannot be LGTM under the code-review policy.

Findings

No actionable inline code findings. inline-findings.json contains an empty JSON array.

Failure-Mode Probing

  • Fractional spacing remains representable as double; the device tests allow the expected one-DIP layout-rounding tolerance.
  • Negative spacing is rejected by the existing bindable-property validation before reaching the handler; this change does not introduce a new nonfinite path.
  • Existing layout-property change handling reapplies spacing, and the added tests cover live linear and grid updates.
  • Both linear orientations, both grid orientations, and the untemplated style path are covered.
  • No subscriptions, async work, handler lifecycle transitions, or shared-state semantics changed.

External Output Contract

Not applicable.

Verdict: NEEDS_DISCUSSION

Confidence: low

Summary: The submitted code and focused regression tests form a coherent fix, and the expert review found no actionable code changes to apply. The verdict is limited only by the skipped gate and unavailable required-check evidence, not by an identified implementation defect.


🛠️ Try-Fix — Analysis & Comparison

Try-Fix Candidate 1 (PR #38960)

Approach: Single-side boundary ownership for item spacing (hypothesis only; no tracked code edits applied due baseline guard).

Prior PR approach avoided and mechanism-level difference: The existing PR halves symmetric spacing values on both adjacent containers (Grid margins, vertical linear margins, horizontal linear padding). This candidate uses a different root-cause model: doubled gaps occur because both neighbors own the same boundary. The alternative mechanism assigns each inter-item boundary to one owner side/container so the full requested spacing is contributed once, avoiding additive doubling without per-side division.

Files changed: None.

Result: Blocked

Exact test command:
pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 -Project Controls -Platform windows -Rebuild -TestFilter "Category=CollectionView" -IncludeClasses "Microsoft.Maui.DeviceTests.CollectionViewTests" -IncludeMethods "LinearItemSpacingMatchesRenderedGap,GridItemSpacingMatchesRenderedGap,UntemplatedLinearItemSpacingIsSharedBetweenAdjacentContainers" -Timeout "00:20:00" -OutputDirectory "CustomAgentLogsTmp\PRState\38960\PRAgent\try-fix\attempt-1\device-test-output"

Test results: Not executed. EstablishBrokenBaseline failed with "No fix files detected" and .github/.baseline-state.json was absent.

Inline self-review count: 0 findings.

Failure analysis: Baseline allow-list state was unavailable, so try-fix safety rules required Blocked before tracked edits or test execution.

Complete candidate diff (from fix.diff):
(no diff)

Try-Fix Candidate 2 (PR #38960)

Approach: Panel-owned layout spacing (hypothesis only; no tracked code edits applied due the baseline guard). The intended mechanism removes item-spacing geometry from GridViewItem/ListViewItem margins and padding, then has the Windows items panel advance between consecutive child layout slots by exactly the requested horizontal or vertical spacing.

PR and candidate-1 approaches avoided and mechanism-level difference: The existing PR divides Grid horizontal/vertical margins, vertical-linear top/bottom margins, and horizontal-linear left/right padding by two, so two symmetric half-contributions add to the requested gap. Candidate 1 instead assigns each boundary to one side/container, which contributes the full requested gap once. Candidate 2 uses neither mechanism: containers contribute zero spacing, no side or container owns an inter-item boundary, and no spacing value is divided. Its distinct root-cause hypothesis is that spacing belongs to the panel's child-placement algorithm rather than the container box model; because the panel computes each next origin from the prior child extent plus one explicit spacing term, adjacent container decorations cannot add and double the gap.

Files changed: None.

Result: Blocked

Exact test command:

pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 -Project Controls -Platform windows -Rebuild -TestFilter "Category=CollectionView" -IncludeClasses "Microsoft.Maui.DeviceTests.CollectionViewTests" -IncludeMethods "LinearItemSpacingMatchesRenderedGap,GridItemSpacingMatchesRenderedGap,UntemplatedLinearItemSpacingIsSharedBetweenAdjacentContainers" -Timeout "00:20:00" -OutputDirectory "CustomAgentLogsTmp\PRState\38960\PRAgent\try-fix\attempt-2\device-test-output"

Test results: Not executed; 0 of the 10 mandatory regression cases ran. EstablishBrokenBaseline.ps1 failed with No fix files detected, emitted no Baseline established marker, and did not create .github.baseline-state.json. The baseline-file boundary therefore required Blocked before tracked edits or device-test execution. No substitute or broader tests were run.

Inline self-review count: 0 findings. The final diff was empty; the expert-review principles, routed Windows CollectionView/native-default guidance, and always-active Logic and Correctness, Regression Prevention, and Complexity Reduction dimensions were reviewed inline.

Failure analysis: The missing baseline state provided no RevertedFiles modification allow-list, so the proposed panel-owned spacing mechanism could not be implemented or empirically evaluated safely. Branches and remote-tracking refs were not manipulated. The mandatory restore command completed with No baseline state found / Restored False, which is the expected no-state completion because no attempt edits were made.

Complete candidate diff (from fix.diff):

(no diff)

🏁 Report — Final Recommendation

⚠️ Final Recommendation: REQUEST CHANGES

Winning candidate

Winner: pr

The submitted PR is the only complete, focused implementation. Its symmetric half-spacing mechanism directly corrects the additive WinUI container geometry while preserving the existing style-based layout model, and the single expert review found no actionable code defect. pr-plus-reviewer is byte-for-byte unchanged from its immutable baseline because the reviewer requested no refinement, so it provides no improvement over pr.

Candidate comparison

Rank Candidate Implementation Regression evidence Review assessment
1 pr Complete four-substitution handler fix, ten focused Windows device cases, and eight updated Windows snapshots The submitted PR metadata reports A/B failure-before/pass-after coverage and current-head Windows device/UI passes; the trusted Gate for this run nevertheless reported SKIPPED — no tests detected No actionable expert finding; best balance of correctness, scope, and compatibility
2 pr-plus-reviewer No reviewer patch; behavior is identical to pr No additional run was warranted because no candidate code changed Valid but strictly redundant, so it cannot displace the raw PR
3 try-fix-1 Single-side boundary ownership was only a hypothesis; no diff exists Blocked before execution; 0 required cases ran Cannot establish correctness, recycling/edge behavior, or an advantage over the submitted fix
4 try-fix-2 Panel-owned spacing was only a hypothesis; no diff exists Blocked before execution; 0 required cases ran Larger conceptual blast radius with no implementation or empirical result

No candidate recorded a regression-test failure. The ordering instead places the implemented candidate with reported focused pass evidence above candidates whose regression tests never ran, as required.

Comparative reasoning

  • Correctness: Each adjacent pair receives S / 2 + S / 2 = S in the existing WinUI box model. The added tests cover vertical/horizontal linear layouts, both grid orientations and axes, zero/fractional/nonzero values, live updates, and the untemplated style path.
  • Compatibility: The raw PR retains symmetric outer-edge spacing and native style inheritance. A one-sided owner would need additional first/last-item, orientation, RTL, and recycling rules; none were implemented or tested.
  • Complexity: Moving spacing into panel child placement would replace the existing container-style mechanism and expand the affected layout surface. Candidate 2 supplied neither code nor evidence to justify that risk.
  • Reviewer refinement: The expert produced [] in inline-findings.json; applying a change merely to create a distinct candidate would reduce confidence rather than improve the fix.

Why this is not an approval

The raw PR wins the implementation comparison, but the hard approval conditions are not met: the trusted Gate was skipped and the expert verdict is NEEDS_DISCUSSION with low confidence because required-check evidence was unavailable. No code change was identified; the blocking gap is verification/test-detection evidence. Approval should wait until that evidence is recognized by the trusted gate or otherwise supplied through the required pipeline.


📱 UI Tests — CollectionView

Detected UI test categories: CollectionView

[!WARNING]
No UI test results were produced for the detected categories. The trusted gate was
skipped before build/test verification, so it does not prove that the PR build is healthy.
The deep UI stage also returned no results; inspect the independent CI checks and retry the
review if those categories still need coverage.


🧭 Next Steps — review latest findings

No alternative fix was selected for this run. Review the session findings and CI results before merging.

@MauiBot MauiBot added s/agent-changes-requested AI agent recommends changes - found a better alternative or issues and removed s/agent-approved AI agent recommends approval - PR fix is correct and optimal s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix) s/agent-review-in-progress AI review is currently running for this PR labels Sep 28, 2026
kubaflo pushed a commit that referenced this pull request Oct 3, 2026
<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Description of Change

Windows CollectionView applied the full requested spacing to both sides
of each item container. Adjacent margins/paddings add, so
`ItemSpacing="30"` produced a **60-DIP gap**, not 30.

Split the requested spacing evenly between the two contributing sides in
`StructuredItemsViewHandler.Windows.cs`:
- Vertical linear layouts: top/bottom margins.
- Horizontal linear layouts: left/right padding.
- Grid layouts: horizontal/vertical margins.

For any finite spacing `S`, the adjacent contributions become `S/2 + S/2
= S`. This is not a DPI correction: WinUI handles scaling of these
logical units. Default zero spacing, the existing symmetric edge-spacing
approach, and native style inheritance are retained. Applications
compensating for the doubled spacing will need to remove that
workaround. This changes the default Windows CollectionView handler, not
the opt-in obsolete compatibility renderer.

### Empirical before/after evidence

The issue's XAML scenario was reproduced in the Sandbox against
repository sources on Windows ARM64. These are actual WinUI-rendered
page captures, not mockups. Native item bounds were measured after
layout.

| Before: requested 30, measured 60 DIPs | After: requested 30, measured
30 DIPs |
|---|---|
| ![Before: CollectionView spacing is
doubled](https://github.com/user-attachments/assets/0c8392d5-a3cf-45f2-a995-eec999981cbf)
| ![After: CollectionView spacing matches the requested
value](https://github.com/user-attachments/assets/393b3caa-bfee-4386-aca9-9a7b9ef27064)
|

Item dimensions stayed **300 × 40 DIPs**. Before, item Y positions were
`30, 130, 230, 330, 430, 530, 630`; after, `15, 85, 155, 225, 295, 365,
435`. All six adjacent gaps changed from 60 to 30 DIPs.

Additional runtime sampling completed **20 captures with zero
geometry-check failures**, including both linear orientations, both grid
orientations, and changing spacing back to zero:

| Requested linear spacing | Measured vertical gap | Measured horizontal
gap |
|---:|---:|---:|
| 0 | 0 | 0 |
| 10 | 10 | 10 |
| 30 | 30 | 30 |
| 7.5 | 8 | 8 |
| 0 after updates | 0 | 0 |

All captures recorded `XamlRoot.RasterizationScale = 1.0` and layout
rounding enabled. The fractional result is **8**, not exactly 7.5, due
to pixel snapping. No other display scale was empirically tested, and no
OS scaling settings were changed.

Grid native-container gaps measured `30/10` for requested
horizontal/vertical spacing `30/10`, in both orientations. Fixed-size
content centered inside a larger grid cell can have additional
whitespace; that is distinct from inter-container spacing.

### Regression coverage and verification

Windows device tests cover rendered linear gaps at zero, fractional, and
nonzero spacing; both grid axes/orientations; live spacing changes; and
untemplated style mapping. The tests measure the current realized native
view wrappers, reacquiring them when a style update replaces item
templates.

The repository's full A/B verification runner completed with
**`VERIFICATION PASSED`**:
- Original framework code: **10 failed, 0 passed** targeted cases.
- Fixed framework code: **10 passed, 0 failed** targeted cases.

The fix and tests were reviewed independently with GPT-5.3-Codex and
GPT-5.6 Sol. Feedback was addressed, and final reviews reported no
remaining actionable findings. The subsequent [independent Windows
review](#38960 (review))
on head `2e987fc48c` also reproduced **10 failures without the fix and
10 passes with it**, with no actionable code-review findings. That
review's own UI stage produced no results; screenshot verification below
comes from the separate public UI pipeline.

### Windows UI baseline updates

The initial [UI build
1614797](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614797)
exposed eight snapshots that encoded the old doubled spacing. Only those
eight Windows baselines were updated from inspected CI captures. Item
sizes, selection indicators, and closed swipe states are preserved; the
changed gutters and resulting content positions reflect the corrected
spacing. For example, `CVHorizontalLinearItemsLayoutItemSpacing` retains
identical item widths while all five measured gaps change from 20 to the
requested 10 pixels.

[Device build
1614798](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614798),
on the preceding code-identical head `5ee75080b0`, passed all ten new
Windows regression cases. Its packaged and unpackaged Windows
CollectionView result files each report **50 passed, 0 failed, 1 known
skip**. After the snapshot updates, a fresh local device run also passed
all ten targeted cases (full CollectionView results: 50 passed, 0
failed, 1 skipped). The current-head [device build
1614911](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614911)
confirmed those same packaged and unpackaged Windows results, including
all ten new regression cases.

Local Appium screenshot verification was blocked by WinAppDriver's
`/status` returning HTTP 500, so none of the eight UI methods ran
locally. **All eight updated screenshot tests passed in [UI build
1614910](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614910)**,
verified from their actual per-test results:
`CVHorizontalLinearItemsLayoutItemSpacing`,
`CollectionViewHeightIsCorrectAfterDelayedLoad`,
`CollectionViewPreSelectionShouldUpdate`,
`CollectionViewSelectionModeOnLightTheme`, `Issue23377ItemSpacing`,
`OnlyManuallySwipedItemShouldBeOpened`,
`VerifyCVBackgroundAndBackgroundColorWithVSM`, and
`VerticalItemsRemainFullyVisibleAfterChangingSpacing`. These are CI
screenshot passes, not an inference from the device tests.

### Build artifacts and CI scope

[Main build
1614908](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614908)
completed successfully. Its **PackageArtifacts** archive contains
`Microsoft.Maui.Controls` and `Microsoft.Maui.Controls.Core` version
**`10.0.120-ci.pr38960.26478.60`**, including the Windows framework
assemblies. Follow [Testing PR
Builds](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) to try
these packages.

The broader device and UI pipelines are **not all green**. Their
non-Windows failures and timed-out retries are tracked separately from
the verified Windows spacing results; the targeted passes above do not
imply whole-suite success.

### Related work

After developing this fix independently, I checked for existing fixes.
#38367 addresses a different untemplated-grid stretching issue in the
.NET 11 handler; it does not correct these additive margins/paddings in
the current Windows handler.

### Issues Fixed

Fixes #38959

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo pushed a commit that referenced this pull request Oct 6, 2026
<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Description of Change

Windows CollectionView applied the full requested spacing to both sides
of each item container. Adjacent margins/paddings add, so
`ItemSpacing="30"` produced a **60-DIP gap**, not 30.

Split the requested spacing evenly between the two contributing sides in
`StructuredItemsViewHandler.Windows.cs`:
- Vertical linear layouts: top/bottom margins.
- Horizontal linear layouts: left/right padding.
- Grid layouts: horizontal/vertical margins.

For any finite spacing `S`, the adjacent contributions become `S/2 + S/2
= S`. This is not a DPI correction: WinUI handles scaling of these
logical units. Default zero spacing, the existing symmetric edge-spacing
approach, and native style inheritance are retained. Applications
compensating for the doubled spacing will need to remove that
workaround. This changes the default Windows CollectionView handler, not
the opt-in obsolete compatibility renderer.

### Empirical before/after evidence

The issue's XAML scenario was reproduced in the Sandbox against
repository sources on Windows ARM64. These are actual WinUI-rendered
page captures, not mockups. Native item bounds were measured after
layout.

| Before: requested 30, measured 60 DIPs | After: requested 30, measured
30 DIPs |
|---|---|
| ![Before: CollectionView spacing is
doubled](https://github.com/user-attachments/assets/0c8392d5-a3cf-45f2-a995-eec999981cbf)
| ![After: CollectionView spacing matches the requested
value](https://github.com/user-attachments/assets/393b3caa-bfee-4386-aca9-9a7b9ef27064)
|

Item dimensions stayed **300 × 40 DIPs**. Before, item Y positions were
`30, 130, 230, 330, 430, 530, 630`; after, `15, 85, 155, 225, 295, 365,
435`. All six adjacent gaps changed from 60 to 30 DIPs.

Additional runtime sampling completed **20 captures with zero
geometry-check failures**, including both linear orientations, both grid
orientations, and changing spacing back to zero:

| Requested linear spacing | Measured vertical gap | Measured horizontal
gap |
|---:|---:|---:|
| 0 | 0 | 0 |
| 10 | 10 | 10 |
| 30 | 30 | 30 |
| 7.5 | 8 | 8 |
| 0 after updates | 0 | 0 |

All captures recorded `XamlRoot.RasterizationScale = 1.0` and layout
rounding enabled. The fractional result is **8**, not exactly 7.5, due
to pixel snapping. No other display scale was empirically tested, and no
OS scaling settings were changed.

Grid native-container gaps measured `30/10` for requested
horizontal/vertical spacing `30/10`, in both orientations. Fixed-size
content centered inside a larger grid cell can have additional
whitespace; that is distinct from inter-container spacing.

### Regression coverage and verification

Windows device tests cover rendered linear gaps at zero, fractional, and
nonzero spacing; both grid axes/orientations; live spacing changes; and
untemplated style mapping. The tests measure the current realized native
view wrappers, reacquiring them when a style update replaces item
templates.

The repository's full A/B verification runner completed with
**`VERIFICATION PASSED`**:
- Original framework code: **10 failed, 0 passed** targeted cases.
- Fixed framework code: **10 passed, 0 failed** targeted cases.

The fix and tests were reviewed independently with GPT-5.3-Codex and
GPT-5.6 Sol. Feedback was addressed, and final reviews reported no
remaining actionable findings. The subsequent [independent Windows
review](#38960 (review))
on head `2e987fc48c` also reproduced **10 failures without the fix and
10 passes with it**, with no actionable code-review findings. That
review's own UI stage produced no results; screenshot verification below
comes from the separate public UI pipeline.

### Windows UI baseline updates

The initial [UI build
1614797](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614797)
exposed eight snapshots that encoded the old doubled spacing. Only those
eight Windows baselines were updated from inspected CI captures. Item
sizes, selection indicators, and closed swipe states are preserved; the
changed gutters and resulting content positions reflect the corrected
spacing. For example, `CVHorizontalLinearItemsLayoutItemSpacing` retains
identical item widths while all five measured gaps change from 20 to the
requested 10 pixels.

[Device build
1614798](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614798),
on the preceding code-identical head `5ee75080b0`, passed all ten new
Windows regression cases. Its packaged and unpackaged Windows
CollectionView result files each report **50 passed, 0 failed, 1 known
skip**. After the snapshot updates, a fresh local device run also passed
all ten targeted cases (full CollectionView results: 50 passed, 0
failed, 1 skipped). The current-head [device build
1614911](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614911)
confirmed those same packaged and unpackaged Windows results, including
all ten new regression cases.

Local Appium screenshot verification was blocked by WinAppDriver's
`/status` returning HTTP 500, so none of the eight UI methods ran
locally. **All eight updated screenshot tests passed in [UI build
1614910](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614910)**,
verified from their actual per-test results:
`CVHorizontalLinearItemsLayoutItemSpacing`,
`CollectionViewHeightIsCorrectAfterDelayedLoad`,
`CollectionViewPreSelectionShouldUpdate`,
`CollectionViewSelectionModeOnLightTheme`, `Issue23377ItemSpacing`,
`OnlyManuallySwipedItemShouldBeOpened`,
`VerifyCVBackgroundAndBackgroundColorWithVSM`, and
`VerticalItemsRemainFullyVisibleAfterChangingSpacing`. These are CI
screenshot passes, not an inference from the device tests.

### Build artifacts and CI scope

[Main build
1614908](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614908)
completed successfully. Its **PackageArtifacts** archive contains
`Microsoft.Maui.Controls` and `Microsoft.Maui.Controls.Core` version
**`10.0.120-ci.pr38960.26478.60`**, including the Windows framework
assemblies. Follow [Testing PR
Builds](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) to try
these packages.

The broader device and UI pipelines are **not all green**. Their
non-Windows failures and timed-out retries are tracked separately from
the verified Windows spacing results; the targeted passes above do not
imply whole-suite success.

### Related work

After developing this fix independently, I checked for existing fixes.
#38367 addresses a different untemplated-grid stretching issue in the
.NET 11 handler; it does not correct these additive margins/paddings in
the current Windows handler.

### Issues Fixed

Fixes #38959

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo pushed a commit that referenced this pull request Oct 13, 2026
<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Description of Change

Windows CollectionView applied the full requested spacing to both sides
of each item container. Adjacent margins/paddings add, so
`ItemSpacing="30"` produced a **60-DIP gap**, not 30.

Split the requested spacing evenly between the two contributing sides in
`StructuredItemsViewHandler.Windows.cs`:
- Vertical linear layouts: top/bottom margins.
- Horizontal linear layouts: left/right padding.
- Grid layouts: horizontal/vertical margins.

For any finite spacing `S`, the adjacent contributions become `S/2 + S/2
= S`. This is not a DPI correction: WinUI handles scaling of these
logical units. Default zero spacing, the existing symmetric edge-spacing
approach, and native style inheritance are retained. Applications
compensating for the doubled spacing will need to remove that
workaround. This changes the default Windows CollectionView handler, not
the opt-in obsolete compatibility renderer.

### Empirical before/after evidence

The issue's XAML scenario was reproduced in the Sandbox against
repository sources on Windows ARM64. These are actual WinUI-rendered
page captures, not mockups. Native item bounds were measured after
layout.

| Before: requested 30, measured 60 DIPs | After: requested 30, measured
30 DIPs |
|---|---|
| ![Before: CollectionView spacing is
doubled](https://github.com/user-attachments/assets/0c8392d5-a3cf-45f2-a995-eec999981cbf)
| ![After: CollectionView spacing matches the requested
value](https://github.com/user-attachments/assets/393b3caa-bfee-4386-aca9-9a7b9ef27064)
|

Item dimensions stayed **300 × 40 DIPs**. Before, item Y positions were
`30, 130, 230, 330, 430, 530, 630`; after, `15, 85, 155, 225, 295, 365,
435`. All six adjacent gaps changed from 60 to 30 DIPs.

Additional runtime sampling completed **20 captures with zero
geometry-check failures**, including both linear orientations, both grid
orientations, and changing spacing back to zero:

| Requested linear spacing | Measured vertical gap | Measured horizontal
gap |
|---:|---:|---:|
| 0 | 0 | 0 |
| 10 | 10 | 10 |
| 30 | 30 | 30 |
| 7.5 | 8 | 8 |
| 0 after updates | 0 | 0 |

All captures recorded `XamlRoot.RasterizationScale = 1.0` and layout
rounding enabled. The fractional result is **8**, not exactly 7.5, due
to pixel snapping. No other display scale was empirically tested, and no
OS scaling settings were changed.

Grid native-container gaps measured `30/10` for requested
horizontal/vertical spacing `30/10`, in both orientations. Fixed-size
content centered inside a larger grid cell can have additional
whitespace; that is distinct from inter-container spacing.

### Regression coverage and verification

Windows device tests cover rendered linear gaps at zero, fractional, and
nonzero spacing; both grid axes/orientations; live spacing changes; and
untemplated style mapping. The tests measure the current realized native
view wrappers, reacquiring them when a style update replaces item
templates.

The repository's full A/B verification runner completed with
**`VERIFICATION PASSED`**:
- Original framework code: **10 failed, 0 passed** targeted cases.
- Fixed framework code: **10 passed, 0 failed** targeted cases.

The fix and tests were reviewed independently with GPT-5.3-Codex and
GPT-5.6 Sol. Feedback was addressed, and final reviews reported no
remaining actionable findings. The subsequent [independent Windows
review](#38960 (review))
on head `2e987fc48c` also reproduced **10 failures without the fix and
10 passes with it**, with no actionable code-review findings. That
review's own UI stage produced no results; screenshot verification below
comes from the separate public UI pipeline.

### Windows UI baseline updates

The initial [UI build
1614797](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614797)
exposed eight snapshots that encoded the old doubled spacing. Only those
eight Windows baselines were updated from inspected CI captures. Item
sizes, selection indicators, and closed swipe states are preserved; the
changed gutters and resulting content positions reflect the corrected
spacing. For example, `CVHorizontalLinearItemsLayoutItemSpacing` retains
identical item widths while all five measured gaps change from 20 to the
requested 10 pixels.

[Device build
1614798](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614798),
on the preceding code-identical head `5ee75080b0`, passed all ten new
Windows regression cases. Its packaged and unpackaged Windows
CollectionView result files each report **50 passed, 0 failed, 1 known
skip**. After the snapshot updates, a fresh local device run also passed
all ten targeted cases (full CollectionView results: 50 passed, 0
failed, 1 skipped). The current-head [device build
1614911](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614911)
confirmed those same packaged and unpackaged Windows results, including
all ten new regression cases.

Local Appium screenshot verification was blocked by WinAppDriver's
`/status` returning HTTP 500, so none of the eight UI methods ran
locally. **All eight updated screenshot tests passed in [UI build
1614910](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614910)**,
verified from their actual per-test results:
`CVHorizontalLinearItemsLayoutItemSpacing`,
`CollectionViewHeightIsCorrectAfterDelayedLoad`,
`CollectionViewPreSelectionShouldUpdate`,
`CollectionViewSelectionModeOnLightTheme`, `Issue23377ItemSpacing`,
`OnlyManuallySwipedItemShouldBeOpened`,
`VerifyCVBackgroundAndBackgroundColorWithVSM`, and
`VerticalItemsRemainFullyVisibleAfterChangingSpacing`. These are CI
screenshot passes, not an inference from the device tests.

### Build artifacts and CI scope

[Main build
1614908](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614908)
completed successfully. Its **PackageArtifacts** archive contains
`Microsoft.Maui.Controls` and `Microsoft.Maui.Controls.Core` version
**`10.0.120-ci.pr38960.26478.60`**, including the Windows framework
assemblies. Follow [Testing PR
Builds](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) to try
these packages.

The broader device and UI pipelines are **not all green**. Their
non-Windows failures and timed-out retries are tracked separately from
the verified Windows spacing results; the targeted passes above do not
imply whole-suite success.

### Related work

After developing this fix independently, I checked for existing fixes.
#38367 addresses a different untemplated-grid stretching issue in the
.NET 11 handler; it does not correct these additive margins/paddings in
the current Windows handler.

### Issues Fixed

Fixes #38959

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo pushed a commit that referenced this pull request Oct 14, 2026
<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Description of Change

Windows CollectionView applied the full requested spacing to both sides
of each item container. Adjacent margins/paddings add, so
`ItemSpacing="30"` produced a **60-DIP gap**, not 30.

Split the requested spacing evenly between the two contributing sides in
`StructuredItemsViewHandler.Windows.cs`:
- Vertical linear layouts: top/bottom margins.
- Horizontal linear layouts: left/right padding.
- Grid layouts: horizontal/vertical margins.

For any finite spacing `S`, the adjacent contributions become `S/2 + S/2
= S`. This is not a DPI correction: WinUI handles scaling of these
logical units. Default zero spacing, the existing symmetric edge-spacing
approach, and native style inheritance are retained. Applications
compensating for the doubled spacing will need to remove that
workaround. This changes the default Windows CollectionView handler, not
the opt-in obsolete compatibility renderer.

### Empirical before/after evidence

The issue's XAML scenario was reproduced in the Sandbox against
repository sources on Windows ARM64. These are actual WinUI-rendered
page captures, not mockups. Native item bounds were measured after
layout.

| Before: requested 30, measured 60 DIPs | After: requested 30, measured
30 DIPs |
|---|---|
| ![Before: CollectionView spacing is
doubled](https://github.com/user-attachments/assets/0c8392d5-a3cf-45f2-a995-eec999981cbf)
| ![After: CollectionView spacing matches the requested
value](https://github.com/user-attachments/assets/393b3caa-bfee-4386-aca9-9a7b9ef27064)
|

Item dimensions stayed **300 × 40 DIPs**. Before, item Y positions were
`30, 130, 230, 330, 430, 530, 630`; after, `15, 85, 155, 225, 295, 365,
435`. All six adjacent gaps changed from 60 to 30 DIPs.

Additional runtime sampling completed **20 captures with zero
geometry-check failures**, including both linear orientations, both grid
orientations, and changing spacing back to zero:

| Requested linear spacing | Measured vertical gap | Measured horizontal
gap |
|---:|---:|---:|
| 0 | 0 | 0 |
| 10 | 10 | 10 |
| 30 | 30 | 30 |
| 7.5 | 8 | 8 |
| 0 after updates | 0 | 0 |

All captures recorded `XamlRoot.RasterizationScale = 1.0` and layout
rounding enabled. The fractional result is **8**, not exactly 7.5, due
to pixel snapping. No other display scale was empirically tested, and no
OS scaling settings were changed.

Grid native-container gaps measured `30/10` for requested
horizontal/vertical spacing `30/10`, in both orientations. Fixed-size
content centered inside a larger grid cell can have additional
whitespace; that is distinct from inter-container spacing.

### Regression coverage and verification

Windows device tests cover rendered linear gaps at zero, fractional, and
nonzero spacing; both grid axes/orientations; live spacing changes; and
untemplated style mapping. The tests measure the current realized native
view wrappers, reacquiring them when a style update replaces item
templates.

The repository's full A/B verification runner completed with
**`VERIFICATION PASSED`**:
- Original framework code: **10 failed, 0 passed** targeted cases.
- Fixed framework code: **10 passed, 0 failed** targeted cases.

The fix and tests were reviewed independently with GPT-5.3-Codex and
GPT-5.6 Sol. Feedback was addressed, and final reviews reported no
remaining actionable findings. The subsequent [independent Windows
review](#38960 (review))
on head `2e987fc48c` also reproduced **10 failures without the fix and
10 passes with it**, with no actionable code-review findings. That
review's own UI stage produced no results; screenshot verification below
comes from the separate public UI pipeline.

### Windows UI baseline updates

The initial [UI build
1614797](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614797)
exposed eight snapshots that encoded the old doubled spacing. Only those
eight Windows baselines were updated from inspected CI captures. Item
sizes, selection indicators, and closed swipe states are preserved; the
changed gutters and resulting content positions reflect the corrected
spacing. For example, `CVHorizontalLinearItemsLayoutItemSpacing` retains
identical item widths while all five measured gaps change from 20 to the
requested 10 pixels.

[Device build
1614798](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614798),
on the preceding code-identical head `5ee75080b0`, passed all ten new
Windows regression cases. Its packaged and unpackaged Windows
CollectionView result files each report **50 passed, 0 failed, 1 known
skip**. After the snapshot updates, a fresh local device run also passed
all ten targeted cases (full CollectionView results: 50 passed, 0
failed, 1 skipped). The current-head [device build
1614911](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614911)
confirmed those same packaged and unpackaged Windows results, including
all ten new regression cases.

Local Appium screenshot verification was blocked by WinAppDriver's
`/status` returning HTTP 500, so none of the eight UI methods ran
locally. **All eight updated screenshot tests passed in [UI build
1614910](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614910)**,
verified from their actual per-test results:
`CVHorizontalLinearItemsLayoutItemSpacing`,
`CollectionViewHeightIsCorrectAfterDelayedLoad`,
`CollectionViewPreSelectionShouldUpdate`,
`CollectionViewSelectionModeOnLightTheme`, `Issue23377ItemSpacing`,
`OnlyManuallySwipedItemShouldBeOpened`,
`VerifyCVBackgroundAndBackgroundColorWithVSM`, and
`VerticalItemsRemainFullyVisibleAfterChangingSpacing`. These are CI
screenshot passes, not an inference from the device tests.

### Build artifacts and CI scope

[Main build
1614908](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614908)
completed successfully. Its **PackageArtifacts** archive contains
`Microsoft.Maui.Controls` and `Microsoft.Maui.Controls.Core` version
**`10.0.120-ci.pr38960.26478.60`**, including the Windows framework
assemblies. Follow [Testing PR
Builds](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) to try
these packages.

The broader device and UI pipelines are **not all green**. Their
non-Windows failures and timed-out retries are tracked separately from
the verified Windows spacing results; the targeted passes above do not
imply whole-suite success.

### Related work

After developing this fix independently, I checked for existing fixes.
#38367 addresses a different untemplated-grid stretching issue in the
.NET 11 handler; it does not correct these additive margins/paddings in
the current Windows handler.

### Issues Fixed

Fixes #38959

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo pushed a commit that referenced this pull request Oct 18, 2026
<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Description of Change

Windows CollectionView applied the full requested spacing to both sides
of each item container. Adjacent margins/paddings add, so
`ItemSpacing="30"` produced a **60-DIP gap**, not 30.

Split the requested spacing evenly between the two contributing sides in
`StructuredItemsViewHandler.Windows.cs`:
- Vertical linear layouts: top/bottom margins.
- Horizontal linear layouts: left/right padding.
- Grid layouts: horizontal/vertical margins.

For any finite spacing `S`, the adjacent contributions become `S/2 + S/2
= S`. This is not a DPI correction: WinUI handles scaling of these
logical units. Default zero spacing, the existing symmetric edge-spacing
approach, and native style inheritance are retained. Applications
compensating for the doubled spacing will need to remove that
workaround. This changes the default Windows CollectionView handler, not
the opt-in obsolete compatibility renderer.

### Empirical before/after evidence

The issue's XAML scenario was reproduced in the Sandbox against
repository sources on Windows ARM64. These are actual WinUI-rendered
page captures, not mockups. Native item bounds were measured after
layout.

| Before: requested 30, measured 60 DIPs | After: requested 30, measured
30 DIPs |
|---|---|
| ![Before: CollectionView spacing is
doubled](https://github.com/user-attachments/assets/0c8392d5-a3cf-45f2-a995-eec999981cbf)
| ![After: CollectionView spacing matches the requested
value](https://github.com/user-attachments/assets/393b3caa-bfee-4386-aca9-9a7b9ef27064)
|

Item dimensions stayed **300 × 40 DIPs**. Before, item Y positions were
`30, 130, 230, 330, 430, 530, 630`; after, `15, 85, 155, 225, 295, 365,
435`. All six adjacent gaps changed from 60 to 30 DIPs.

Additional runtime sampling completed **20 captures with zero
geometry-check failures**, including both linear orientations, both grid
orientations, and changing spacing back to zero:

| Requested linear spacing | Measured vertical gap | Measured horizontal
gap |
|---:|---:|---:|
| 0 | 0 | 0 |
| 10 | 10 | 10 |
| 30 | 30 | 30 |
| 7.5 | 8 | 8 |
| 0 after updates | 0 | 0 |

All captures recorded `XamlRoot.RasterizationScale = 1.0` and layout
rounding enabled. The fractional result is **8**, not exactly 7.5, due
to pixel snapping. No other display scale was empirically tested, and no
OS scaling settings were changed.

Grid native-container gaps measured `30/10` for requested
horizontal/vertical spacing `30/10`, in both orientations. Fixed-size
content centered inside a larger grid cell can have additional
whitespace; that is distinct from inter-container spacing.

### Regression coverage and verification

Windows device tests cover rendered linear gaps at zero, fractional, and
nonzero spacing; both grid axes/orientations; live spacing changes; and
untemplated style mapping. The tests measure the current realized native
view wrappers, reacquiring them when a style update replaces item
templates.

The repository's full A/B verification runner completed with
**`VERIFICATION PASSED`**:
- Original framework code: **10 failed, 0 passed** targeted cases.
- Fixed framework code: **10 passed, 0 failed** targeted cases.

The fix and tests were reviewed independently with GPT-5.3-Codex and
GPT-5.6 Sol. Feedback was addressed, and final reviews reported no
remaining actionable findings. The subsequent [independent Windows
review](#38960 (review))
on head `2e987fc48c` also reproduced **10 failures without the fix and
10 passes with it**, with no actionable code-review findings. That
review's own UI stage produced no results; screenshot verification below
comes from the separate public UI pipeline.

### Windows UI baseline updates

The initial [UI build
1614797](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614797)
exposed eight snapshots that encoded the old doubled spacing. Only those
eight Windows baselines were updated from inspected CI captures. Item
sizes, selection indicators, and closed swipe states are preserved; the
changed gutters and resulting content positions reflect the corrected
spacing. For example, `CVHorizontalLinearItemsLayoutItemSpacing` retains
identical item widths while all five measured gaps change from 20 to the
requested 10 pixels.

[Device build
1614798](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614798),
on the preceding code-identical head `5ee75080b0`, passed all ten new
Windows regression cases. Its packaged and unpackaged Windows
CollectionView result files each report **50 passed, 0 failed, 1 known
skip**. After the snapshot updates, a fresh local device run also passed
all ten targeted cases (full CollectionView results: 50 passed, 0
failed, 1 skipped). The current-head [device build
1614911](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614911)
confirmed those same packaged and unpackaged Windows results, including
all ten new regression cases.

Local Appium screenshot verification was blocked by WinAppDriver's
`/status` returning HTTP 500, so none of the eight UI methods ran
locally. **All eight updated screenshot tests passed in [UI build
1614910](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614910)**,
verified from their actual per-test results:
`CVHorizontalLinearItemsLayoutItemSpacing`,
`CollectionViewHeightIsCorrectAfterDelayedLoad`,
`CollectionViewPreSelectionShouldUpdate`,
`CollectionViewSelectionModeOnLightTheme`, `Issue23377ItemSpacing`,
`OnlyManuallySwipedItemShouldBeOpened`,
`VerifyCVBackgroundAndBackgroundColorWithVSM`, and
`VerticalItemsRemainFullyVisibleAfterChangingSpacing`. These are CI
screenshot passes, not an inference from the device tests.

### Build artifacts and CI scope

[Main build
1614908](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614908)
completed successfully. Its **PackageArtifacts** archive contains
`Microsoft.Maui.Controls` and `Microsoft.Maui.Controls.Core` version
**`10.0.120-ci.pr38960.26478.60`**, including the Windows framework
assemblies. Follow [Testing PR
Builds](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) to try
these packages.

The broader device and UI pipelines are **not all green**. Their
non-Windows failures and timed-out retries are tracked separately from
the verified Windows spacing results; the targeted passes above do not
imply whole-suite success.

### Related work

After developing this fix independently, I checked for existing fixes.
#38367 addresses a different untemplated-grid stretching issue in the
.NET 11 handler; it does not correct these additive margins/paddings in
the current Windows handler.

### Issues Fixed

Fixes #38959

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo pushed a commit that referenced this pull request Oct 21, 2026
<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Description of Change

Windows CollectionView applied the full requested spacing to both sides
of each item container. Adjacent margins/paddings add, so
`ItemSpacing="30"` produced a **60-DIP gap**, not 30.

Split the requested spacing evenly between the two contributing sides in
`StructuredItemsViewHandler.Windows.cs`:
- Vertical linear layouts: top/bottom margins.
- Horizontal linear layouts: left/right padding.
- Grid layouts: horizontal/vertical margins.

For any finite spacing `S`, the adjacent contributions become `S/2 + S/2
= S`. This is not a DPI correction: WinUI handles scaling of these
logical units. Default zero spacing, the existing symmetric edge-spacing
approach, and native style inheritance are retained. Applications
compensating for the doubled spacing will need to remove that
workaround. This changes the default Windows CollectionView handler, not
the opt-in obsolete compatibility renderer.

### Empirical before/after evidence

The issue's XAML scenario was reproduced in the Sandbox against
repository sources on Windows ARM64. These are actual WinUI-rendered
page captures, not mockups. Native item bounds were measured after
layout.

| Before: requested 30, measured 60 DIPs | After: requested 30, measured
30 DIPs |
|---|---|
| ![Before: CollectionView spacing is
doubled](https://github.com/user-attachments/assets/0c8392d5-a3cf-45f2-a995-eec999981cbf)
| ![After: CollectionView spacing matches the requested
value](https://github.com/user-attachments/assets/393b3caa-bfee-4386-aca9-9a7b9ef27064)
|

Item dimensions stayed **300 × 40 DIPs**. Before, item Y positions were
`30, 130, 230, 330, 430, 530, 630`; after, `15, 85, 155, 225, 295, 365,
435`. All six adjacent gaps changed from 60 to 30 DIPs.

Additional runtime sampling completed **20 captures with zero
geometry-check failures**, including both linear orientations, both grid
orientations, and changing spacing back to zero:

| Requested linear spacing | Measured vertical gap | Measured horizontal
gap |
|---:|---:|---:|
| 0 | 0 | 0 |
| 10 | 10 | 10 |
| 30 | 30 | 30 |
| 7.5 | 8 | 8 |
| 0 after updates | 0 | 0 |

All captures recorded `XamlRoot.RasterizationScale = 1.0` and layout
rounding enabled. The fractional result is **8**, not exactly 7.5, due
to pixel snapping. No other display scale was empirically tested, and no
OS scaling settings were changed.

Grid native-container gaps measured `30/10` for requested
horizontal/vertical spacing `30/10`, in both orientations. Fixed-size
content centered inside a larger grid cell can have additional
whitespace; that is distinct from inter-container spacing.

### Regression coverage and verification

Windows device tests cover rendered linear gaps at zero, fractional, and
nonzero spacing; both grid axes/orientations; live spacing changes; and
untemplated style mapping. The tests measure the current realized native
view wrappers, reacquiring them when a style update replaces item
templates.

The repository's full A/B verification runner completed with
**`VERIFICATION PASSED`**:
- Original framework code: **10 failed, 0 passed** targeted cases.
- Fixed framework code: **10 passed, 0 failed** targeted cases.

The fix and tests were reviewed independently with GPT-5.3-Codex and
GPT-5.6 Sol. Feedback was addressed, and final reviews reported no
remaining actionable findings. The subsequent [independent Windows
review](#38960 (review))
on head `2e987fc48c` also reproduced **10 failures without the fix and
10 passes with it**, with no actionable code-review findings. That
review's own UI stage produced no results; screenshot verification below
comes from the separate public UI pipeline.

### Windows UI baseline updates

The initial [UI build
1614797](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614797)
exposed eight snapshots that encoded the old doubled spacing. Only those
eight Windows baselines were updated from inspected CI captures. Item
sizes, selection indicators, and closed swipe states are preserved; the
changed gutters and resulting content positions reflect the corrected
spacing. For example, `CVHorizontalLinearItemsLayoutItemSpacing` retains
identical item widths while all five measured gaps change from 20 to the
requested 10 pixels.

[Device build
1614798](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614798),
on the preceding code-identical head `5ee75080b0`, passed all ten new
Windows regression cases. Its packaged and unpackaged Windows
CollectionView result files each report **50 passed, 0 failed, 1 known
skip**. After the snapshot updates, a fresh local device run also passed
all ten targeted cases (full CollectionView results: 50 passed, 0
failed, 1 skipped). The current-head [device build
1614911](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614911)
confirmed those same packaged and unpackaged Windows results, including
all ten new regression cases.

Local Appium screenshot verification was blocked by WinAppDriver's
`/status` returning HTTP 500, so none of the eight UI methods ran
locally. **All eight updated screenshot tests passed in [UI build
1614910](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614910)**,
verified from their actual per-test results:
`CVHorizontalLinearItemsLayoutItemSpacing`,
`CollectionViewHeightIsCorrectAfterDelayedLoad`,
`CollectionViewPreSelectionShouldUpdate`,
`CollectionViewSelectionModeOnLightTheme`, `Issue23377ItemSpacing`,
`OnlyManuallySwipedItemShouldBeOpened`,
`VerifyCVBackgroundAndBackgroundColorWithVSM`, and
`VerticalItemsRemainFullyVisibleAfterChangingSpacing`. These are CI
screenshot passes, not an inference from the device tests.

### Build artifacts and CI scope

[Main build
1614908](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614908)
completed successfully. Its **PackageArtifacts** archive contains
`Microsoft.Maui.Controls` and `Microsoft.Maui.Controls.Core` version
**`10.0.120-ci.pr38960.26478.60`**, including the Windows framework
assemblies. Follow [Testing PR
Builds](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) to try
these packages.

The broader device and UI pipelines are **not all green**. Their
non-Windows failures and timed-out retries are tracked separately from
the verified Windows spacing results; the targeted passes above do not
imply whole-suite success.

### Related work

After developing this fix independently, I checked for existing fixes.
#38367 addresses a different untemplated-grid stretching issue in the
.NET 11 handler; it does not correct these additive margins/paddings in
the current Windows handler.

### Issues Fixed

Fixes #38959

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo pushed a commit that referenced this pull request Oct 25, 2026
<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Description of Change

Windows CollectionView applied the full requested spacing to both sides
of each item container. Adjacent margins/paddings add, so
`ItemSpacing="30"` produced a **60-DIP gap**, not 30.

Split the requested spacing evenly between the two contributing sides in
`StructuredItemsViewHandler.Windows.cs`:
- Vertical linear layouts: top/bottom margins.
- Horizontal linear layouts: left/right padding.
- Grid layouts: horizontal/vertical margins.

For any finite spacing `S`, the adjacent contributions become `S/2 + S/2
= S`. This is not a DPI correction: WinUI handles scaling of these
logical units. Default zero spacing, the existing symmetric edge-spacing
approach, and native style inheritance are retained. Applications
compensating for the doubled spacing will need to remove that
workaround. This changes the default Windows CollectionView handler, not
the opt-in obsolete compatibility renderer.

### Empirical before/after evidence

The issue's XAML scenario was reproduced in the Sandbox against
repository sources on Windows ARM64. These are actual WinUI-rendered
page captures, not mockups. Native item bounds were measured after
layout.

| Before: requested 30, measured 60 DIPs | After: requested 30, measured
30 DIPs |
|---|---|
| ![Before: CollectionView spacing is
doubled](https://github.com/user-attachments/assets/0c8392d5-a3cf-45f2-a995-eec999981cbf)
| ![After: CollectionView spacing matches the requested
value](https://github.com/user-attachments/assets/393b3caa-bfee-4386-aca9-9a7b9ef27064)
|

Item dimensions stayed **300 × 40 DIPs**. Before, item Y positions were
`30, 130, 230, 330, 430, 530, 630`; after, `15, 85, 155, 225, 295, 365,
435`. All six adjacent gaps changed from 60 to 30 DIPs.

Additional runtime sampling completed **20 captures with zero
geometry-check failures**, including both linear orientations, both grid
orientations, and changing spacing back to zero:

| Requested linear spacing | Measured vertical gap | Measured horizontal
gap |
|---:|---:|---:|
| 0 | 0 | 0 |
| 10 | 10 | 10 |
| 30 | 30 | 30 |
| 7.5 | 8 | 8 |
| 0 after updates | 0 | 0 |

All captures recorded `XamlRoot.RasterizationScale = 1.0` and layout
rounding enabled. The fractional result is **8**, not exactly 7.5, due
to pixel snapping. No other display scale was empirically tested, and no
OS scaling settings were changed.

Grid native-container gaps measured `30/10` for requested
horizontal/vertical spacing `30/10`, in both orientations. Fixed-size
content centered inside a larger grid cell can have additional
whitespace; that is distinct from inter-container spacing.

### Regression coverage and verification

Windows device tests cover rendered linear gaps at zero, fractional, and
nonzero spacing; both grid axes/orientations; live spacing changes; and
untemplated style mapping. The tests measure the current realized native
view wrappers, reacquiring them when a style update replaces item
templates.

The repository's full A/B verification runner completed with
**`VERIFICATION PASSED`**:
- Original framework code: **10 failed, 0 passed** targeted cases.
- Fixed framework code: **10 passed, 0 failed** targeted cases.

The fix and tests were reviewed independently with GPT-5.3-Codex and
GPT-5.6 Sol. Feedback was addressed, and final reviews reported no
remaining actionable findings. The subsequent [independent Windows
review](#38960 (review))
on head `2e987fc48c` also reproduced **10 failures without the fix and
10 passes with it**, with no actionable code-review findings. That
review's own UI stage produced no results; screenshot verification below
comes from the separate public UI pipeline.

### Windows UI baseline updates

The initial [UI build
1614797](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614797)
exposed eight snapshots that encoded the old doubled spacing. Only those
eight Windows baselines were updated from inspected CI captures. Item
sizes, selection indicators, and closed swipe states are preserved; the
changed gutters and resulting content positions reflect the corrected
spacing. For example, `CVHorizontalLinearItemsLayoutItemSpacing` retains
identical item widths while all five measured gaps change from 20 to the
requested 10 pixels.

[Device build
1614798](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614798),
on the preceding code-identical head `5ee75080b0`, passed all ten new
Windows regression cases. Its packaged and unpackaged Windows
CollectionView result files each report **50 passed, 0 failed, 1 known
skip**. After the snapshot updates, a fresh local device run also passed
all ten targeted cases (full CollectionView results: 50 passed, 0
failed, 1 skipped). The current-head [device build
1614911](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614911)
confirmed those same packaged and unpackaged Windows results, including
all ten new regression cases.

Local Appium screenshot verification was blocked by WinAppDriver's
`/status` returning HTTP 500, so none of the eight UI methods ran
locally. **All eight updated screenshot tests passed in [UI build
1614910](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614910)**,
verified from their actual per-test results:
`CVHorizontalLinearItemsLayoutItemSpacing`,
`CollectionViewHeightIsCorrectAfterDelayedLoad`,
`CollectionViewPreSelectionShouldUpdate`,
`CollectionViewSelectionModeOnLightTheme`, `Issue23377ItemSpacing`,
`OnlyManuallySwipedItemShouldBeOpened`,
`VerifyCVBackgroundAndBackgroundColorWithVSM`, and
`VerticalItemsRemainFullyVisibleAfterChangingSpacing`. These are CI
screenshot passes, not an inference from the device tests.

### Build artifacts and CI scope

[Main build
1614908](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614908)
completed successfully. Its **PackageArtifacts** archive contains
`Microsoft.Maui.Controls` and `Microsoft.Maui.Controls.Core` version
**`10.0.120-ci.pr38960.26478.60`**, including the Windows framework
assemblies. Follow [Testing PR
Builds](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) to try
these packages.

The broader device and UI pipelines are **not all green**. Their
non-Windows failures and timed-out retries are tracked separately from
the verified Windows spacing results; the targeted passes above do not
imply whole-suite success.

### Related work

After developing this fix independently, I checked for existing fixes.
#38367 addresses a different untemplated-grid stretching issue in the
.NET 11 handler; it does not correct these additive margins/paddings in
the current Windows handler.

### Issues Fixed

Fixes #38959

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo pushed a commit that referenced this pull request Oct 26, 2026
<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Description of Change

Windows CollectionView applied the full requested spacing to both sides
of each item container. Adjacent margins/paddings add, so
`ItemSpacing="30"` produced a **60-DIP gap**, not 30.

Split the requested spacing evenly between the two contributing sides in
`StructuredItemsViewHandler.Windows.cs`:
- Vertical linear layouts: top/bottom margins.
- Horizontal linear layouts: left/right padding.
- Grid layouts: horizontal/vertical margins.

For any finite spacing `S`, the adjacent contributions become `S/2 + S/2
= S`. This is not a DPI correction: WinUI handles scaling of these
logical units. Default zero spacing, the existing symmetric edge-spacing
approach, and native style inheritance are retained. Applications
compensating for the doubled spacing will need to remove that
workaround. This changes the default Windows CollectionView handler, not
the opt-in obsolete compatibility renderer.

### Empirical before/after evidence

The issue's XAML scenario was reproduced in the Sandbox against
repository sources on Windows ARM64. These are actual WinUI-rendered
page captures, not mockups. Native item bounds were measured after
layout.

| Before: requested 30, measured 60 DIPs | After: requested 30, measured
30 DIPs |
|---|---|
| ![Before: CollectionView spacing is
doubled](https://github.com/user-attachments/assets/0c8392d5-a3cf-45f2-a995-eec999981cbf)
| ![After: CollectionView spacing matches the requested
value](https://github.com/user-attachments/assets/393b3caa-bfee-4386-aca9-9a7b9ef27064)
|

Item dimensions stayed **300 × 40 DIPs**. Before, item Y positions were
`30, 130, 230, 330, 430, 530, 630`; after, `15, 85, 155, 225, 295, 365,
435`. All six adjacent gaps changed from 60 to 30 DIPs.

Additional runtime sampling completed **20 captures with zero
geometry-check failures**, including both linear orientations, both grid
orientations, and changing spacing back to zero:

| Requested linear spacing | Measured vertical gap | Measured horizontal
gap |
|---:|---:|---:|
| 0 | 0 | 0 |
| 10 | 10 | 10 |
| 30 | 30 | 30 |
| 7.5 | 8 | 8 |
| 0 after updates | 0 | 0 |

All captures recorded `XamlRoot.RasterizationScale = 1.0` and layout
rounding enabled. The fractional result is **8**, not exactly 7.5, due
to pixel snapping. No other display scale was empirically tested, and no
OS scaling settings were changed.

Grid native-container gaps measured `30/10` for requested
horizontal/vertical spacing `30/10`, in both orientations. Fixed-size
content centered inside a larger grid cell can have additional
whitespace; that is distinct from inter-container spacing.

### Regression coverage and verification

Windows device tests cover rendered linear gaps at zero, fractional, and
nonzero spacing; both grid axes/orientations; live spacing changes; and
untemplated style mapping. The tests measure the current realized native
view wrappers, reacquiring them when a style update replaces item
templates.

The repository's full A/B verification runner completed with
**`VERIFICATION PASSED`**:
- Original framework code: **10 failed, 0 passed** targeted cases.
- Fixed framework code: **10 passed, 0 failed** targeted cases.

The fix and tests were reviewed independently with GPT-5.3-Codex and
GPT-5.6 Sol. Feedback was addressed, and final reviews reported no
remaining actionable findings. The subsequent [independent Windows
review](#38960 (review))
on head `2e987fc48c` also reproduced **10 failures without the fix and
10 passes with it**, with no actionable code-review findings. That
review's own UI stage produced no results; screenshot verification below
comes from the separate public UI pipeline.

### Windows UI baseline updates

The initial [UI build
1614797](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614797)
exposed eight snapshots that encoded the old doubled spacing. Only those
eight Windows baselines were updated from inspected CI captures. Item
sizes, selection indicators, and closed swipe states are preserved; the
changed gutters and resulting content positions reflect the corrected
spacing. For example, `CVHorizontalLinearItemsLayoutItemSpacing` retains
identical item widths while all five measured gaps change from 20 to the
requested 10 pixels.

[Device build
1614798](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614798),
on the preceding code-identical head `5ee75080b0`, passed all ten new
Windows regression cases. Its packaged and unpackaged Windows
CollectionView result files each report **50 passed, 0 failed, 1 known
skip**. After the snapshot updates, a fresh local device run also passed
all ten targeted cases (full CollectionView results: 50 passed, 0
failed, 1 skipped). The current-head [device build
1614911](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614911)
confirmed those same packaged and unpackaged Windows results, including
all ten new regression cases.

Local Appium screenshot verification was blocked by WinAppDriver's
`/status` returning HTTP 500, so none of the eight UI methods ran
locally. **All eight updated screenshot tests passed in [UI build
1614910](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614910)**,
verified from their actual per-test results:
`CVHorizontalLinearItemsLayoutItemSpacing`,
`CollectionViewHeightIsCorrectAfterDelayedLoad`,
`CollectionViewPreSelectionShouldUpdate`,
`CollectionViewSelectionModeOnLightTheme`, `Issue23377ItemSpacing`,
`OnlyManuallySwipedItemShouldBeOpened`,
`VerifyCVBackgroundAndBackgroundColorWithVSM`, and
`VerticalItemsRemainFullyVisibleAfterChangingSpacing`. These are CI
screenshot passes, not an inference from the device tests.

### Build artifacts and CI scope

[Main build
1614908](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614908)
completed successfully. Its **PackageArtifacts** archive contains
`Microsoft.Maui.Controls` and `Microsoft.Maui.Controls.Core` version
**`10.0.120-ci.pr38960.26478.60`**, including the Windows framework
assemblies. Follow [Testing PR
Builds](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) to try
these packages.

The broader device and UI pipelines are **not all green**. Their
non-Windows failures and timed-out retries are tracked separately from
the verified Windows spacing results; the targeted passes above do not
imply whole-suite success.

### Related work

After developing this fix independently, I checked for existing fixes.
#38367 addresses a different untemplated-grid stretching issue in the
.NET 11 handler; it does not correct these additive margins/paddings in
the current Windows handler.

### Issues Fixed

Fixes #38959

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
github-actions Bot pushed a commit that referenced this pull request Oct 28, 2026
<!-- Please let the below note in for people that find this PR -->
> [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Description of Change

Windows CollectionView applied the full requested spacing to both sides
of each item container. Adjacent margins/paddings add, so
`ItemSpacing="30"` produced a **60-DIP gap**, not 30.

Split the requested spacing evenly between the two contributing sides in
`StructuredItemsViewHandler.Windows.cs`:
- Vertical linear layouts: top/bottom margins.
- Horizontal linear layouts: left/right padding.
- Grid layouts: horizontal/vertical margins.

For any finite spacing `S`, the adjacent contributions become `S/2 + S/2
= S`. This is not a DPI correction: WinUI handles scaling of these
logical units. Default zero spacing, the existing symmetric edge-spacing
approach, and native style inheritance are retained. Applications
compensating for the doubled spacing will need to remove that
workaround. This changes the default Windows CollectionView handler, not
the opt-in obsolete compatibility renderer.

### Empirical before/after evidence

The issue's XAML scenario was reproduced in the Sandbox against
repository sources on Windows ARM64. These are actual WinUI-rendered
page captures, not mockups. Native item bounds were measured after
layout.

| Before: requested 30, measured 60 DIPs | After: requested 30, measured
30 DIPs |
|---|---|
| ![Before: CollectionView spacing is
doubled](https://github.com/user-attachments/assets/0c8392d5-a3cf-45f2-a995-eec999981cbf)
| ![After: CollectionView spacing matches the requested
value](https://github.com/user-attachments/assets/393b3caa-bfee-4386-aca9-9a7b9ef27064)
|

Item dimensions stayed **300 × 40 DIPs**. Before, item Y positions were
`30, 130, 230, 330, 430, 530, 630`; after, `15, 85, 155, 225, 295, 365,
435`. All six adjacent gaps changed from 60 to 30 DIPs.

Additional runtime sampling completed **20 captures with zero
geometry-check failures**, including both linear orientations, both grid
orientations, and changing spacing back to zero:

| Requested linear spacing | Measured vertical gap | Measured horizontal
gap |
|---:|---:|---:|
| 0 | 0 | 0 |
| 10 | 10 | 10 |
| 30 | 30 | 30 |
| 7.5 | 8 | 8 |
| 0 after updates | 0 | 0 |

All captures recorded `XamlRoot.RasterizationScale = 1.0` and layout
rounding enabled. The fractional result is **8**, not exactly 7.5, due
to pixel snapping. No other display scale was empirically tested, and no
OS scaling settings were changed.

Grid native-container gaps measured `30/10` for requested
horizontal/vertical spacing `30/10`, in both orientations. Fixed-size
content centered inside a larger grid cell can have additional
whitespace; that is distinct from inter-container spacing.

### Regression coverage and verification

Windows device tests cover rendered linear gaps at zero, fractional, and
nonzero spacing; both grid axes/orientations; live spacing changes; and
untemplated style mapping. The tests measure the current realized native
view wrappers, reacquiring them when a style update replaces item
templates.

The repository's full A/B verification runner completed with
**`VERIFICATION PASSED`**:
- Original framework code: **10 failed, 0 passed** targeted cases.
- Fixed framework code: **10 passed, 0 failed** targeted cases.

The fix and tests were reviewed independently with GPT-5.3-Codex and
GPT-5.6 Sol. Feedback was addressed, and final reviews reported no
remaining actionable findings. The subsequent [independent Windows
review](#38960 (review))
on head `2e987fc48c` also reproduced **10 failures without the fix and
10 passes with it**, with no actionable code-review findings. That
review's own UI stage produced no results; screenshot verification below
comes from the separate public UI pipeline.

### Windows UI baseline updates

The initial [UI build
1614797](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614797)
exposed eight snapshots that encoded the old doubled spacing. Only those
eight Windows baselines were updated from inspected CI captures. Item
sizes, selection indicators, and closed swipe states are preserved; the
changed gutters and resulting content positions reflect the corrected
spacing. For example, `CVHorizontalLinearItemsLayoutItemSpacing` retains
identical item widths while all five measured gaps change from 20 to the
requested 10 pixels.

[Device build
1614798](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614798),
on the preceding code-identical head `5ee75080b0`, passed all ten new
Windows regression cases. Its packaged and unpackaged Windows
CollectionView result files each report **50 passed, 0 failed, 1 known
skip**. After the snapshot updates, a fresh local device run also passed
all ten targeted cases (full CollectionView results: 50 passed, 0
failed, 1 skipped). The current-head [device build
1614911](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614911)
confirmed those same packaged and unpackaged Windows results, including
all ten new regression cases.

Local Appium screenshot verification was blocked by WinAppDriver's
`/status` returning HTTP 500, so none of the eight UI methods ran
locally. **All eight updated screenshot tests passed in [UI build
1614910](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614910)**,
verified from their actual per-test results:
`CVHorizontalLinearItemsLayoutItemSpacing`,
`CollectionViewHeightIsCorrectAfterDelayedLoad`,
`CollectionViewPreSelectionShouldUpdate`,
`CollectionViewSelectionModeOnLightTheme`, `Issue23377ItemSpacing`,
`OnlyManuallySwipedItemShouldBeOpened`,
`VerifyCVBackgroundAndBackgroundColorWithVSM`, and
`VerticalItemsRemainFullyVisibleAfterChangingSpacing`. These are CI
screenshot passes, not an inference from the device tests.

### Build artifacts and CI scope

[Main build
1614908](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1614908)
completed successfully. Its **PackageArtifacts** archive contains
`Microsoft.Maui.Controls` and `Microsoft.Maui.Controls.Core` version
**`10.0.120-ci.pr38960.26478.60`**, including the Windows framework
assemblies. Follow [Testing PR
Builds](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) to try
these packages.

The broader device and UI pipelines are **not all green**. Their
non-Windows failures and timed-out retries are tracked separately from
the verified Windows spacing results; the targeted passes above do not
imply whole-suite success.

### Related work

After developing this fix independently, I checked for existing fixes.
#38367 addresses a different untemplated-grid stretching issue in the
.NET 11 handler; it does not correct these additive margins/paddings in
the current Windows handler.

### Issues Fixed

Fixes #38959

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-fix-pr-picked AI could not beat the PR fix - PR is the best among all candidates s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CollectionView.ItemsLayout LinearItemsLayout ItemSpacing behaves significantly differently on Windows compared to Android (possibly Mac/iOS too)

4 participants