Skip to content

[net 11] [Windows] Fix excessive spacing in untemplated CollectionView vertical grids - #38367

Merged
kubaflo merged 8 commits into
dotnet:net11.0from
Shalini-Ashokan:fix-38059
Oct 7, 2026
Merged

kubaflo merged 8 commits into
dotnet:net11.0from
Shalini-Ashokan:fix-38059

Conversation

@Shalini-Ashokan

Copy link
Copy Markdown
Contributor

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Issue Details

On Windows, a CollectionView vertical grid without an ItemTemplate displays very large gaps between rows.
This makes simple text items appear far apart instead of forming a compact grid.

Root Cause

WinUI UniformGridLayoutItemsStretch.Uniform increases both item width and height to preserve item shape.
When text items become wider, their row height also grows and creates unwanted empty space.

Description of Change

Use Fill for vertical grids so items fill the column width but keep their natural height.

Validated the behavior in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Issues Fixed

Fixes #38059

Output ScreenShot

Before After
image image

@github-actions

github-actions Bot commented Sep 9, 2026

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 -- 38367

Or

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

@dotnet-policy-service dotnet-policy-service Bot added the community ✨ Community Contribution label Sep 9, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hey there @@Shalini-Ashokan! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

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

@vishnumenon2684

Copy link
Copy Markdown
Contributor

/azp run maui-pr-uitests , maui-pr-devicetests

@azure-pipelines

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

@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 10, 2026
MauiBot

This comment was marked as outdated.

@MauiBot MauiBot added 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) and removed s/agent-review-in-progress AI review is currently running for this PR labels Sep 10, 2026
@vishnumenon2684

Copy link
Copy Markdown
Contributor

/azp run maui-pr-uitests , maui-pr-devicetests

@azure-pipelines

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

@vishnumenon2684

Copy link
Copy Markdown
Contributor

/azp run maui-pr-uitests , maui-pr-devicetests

@kubaflo

kubaflo commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

/azp run

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Note

🔍 /review started

AzDO build 15531393 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.

@azure-pipelines

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

@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

@Shalini-Ashokan — new AI review results are available based on commit bba199f.

Gate Passed Confidence Medium Platform Windows


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

Gate Result: ✅ PASSED

Platform: WINDOWS · Base: net11.0 · Merge base: d06cbd11

Test Without Fix (expect FAIL) With Fix (expect PASS)
🖥️ Issue38059 Issue38059 ✅ FAIL — 529s ✅ PASS — 285s
🔴 Without fix — 🖥️ Issue38059: FAIL ✅ · 529s

Error-relevant lines (filtered from the build log):

     at VisualTestUtils.VisualRegressionTester.Fail(String message) in /_/src/TestUtils/src/VisualTestUtils/VisualRegressionTester.cs:line 162
   at VisualTestUtils.VisualRegressionTester.VerifyMatchesSnapshot(String name, ImageSnapshot actualImage, String environmentName, ITestContext testContext) in /_/src/TestUtils/src/VisualTestUtils/VisualRegressionTester.cs:line 123
   at Microsoft.Maui.TestCases.Tests.UITest.<VerifyScreenshot>g__Verify|13_0(String name, <>c__DisplayClass13_0&) in /_/src/Controls/tests/TestCases.Shared.Tests/UITest.cs:line 488
   at Microsoft.Maui.TestCases.Tests.UITest.VerifyScreenshot(String name, Nullable`1 retryDelay, Nullable`1 retryTimeout, Int32 cropLeft, Int32 cropRight, Int32 cropTop, Int32 cropBottom, Double tolerance, Boolean includeTitleBar) in /_/src/Controls/tests/TestCases.Shared.Tests/UITest.cs:line 312
   at Microsoft.Maui.TestCases.Tests.Issues.Issue38059.Issue38059_UntemplatedVerticalGridLayout() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue38059.cs:line 20
   at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
🟢 With fix — 🖥️ Issue38059: PASS ✅ · 285s

(no coded error found; showing last 1200 chars)

s.TestCases.WinUI.Tests\Debug\net11.0\Controls.TestCases.WinUI.Tests.dll
   NUnit3TestExecutor discovered 2 of 2 NUnit test cases using Current Discovery mode, Non-Explicit run
>>>>> 10/1/2026 7:20:26 AM FixtureSetup for Issue38059(Windows)
>>>>> 10/1/2026 7:20:33 AM Issue38059_UntemplatedVerticalGridLayout Start
>>>>> 10/1/2026 7:20:34 AM Issue38059_UntemplatedVerticalGridLayout Stop
>>>>> 10/1/2026 7:20:34 AM Issue38059_UntemplatedHorizontalGridLayout Start
  Passed Issue38059_UntemplatedVerticalGridLayout [1 s]
>>>>> 10/1/2026 7:20:36 AM Issue38059_UntemplatedHorizontalGridLayout Stop
  Passed Issue38059_UntemplatedHorizontalGridLayout [1 s]
NUnit Adapter 4.5.0.0: Test execution complete
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.2+699d445a1a (64-bit .NET 11.0.0-rtm.26479.103)
[xUnit.net 00:00:00.11]   Discovering: Controls.TestCases.WinUI.Tests
[xUnit.net 00:00:00.33]   Discovered:  Controls.TestCases.WinUI.Tests
Results File: D:\a\1\s\CustomAgentLogsTmp\UITests\TestResults\Issue38059.trx
Test Run Successful.
Total tests: 2
     Passed: 2
 Total time: 20.7895 Seconds
>>> TRX_RESULT_FILE: D:\a\1\s\CustomAgentLogsTmp\UITests\TestResults\Issue38059.trx
📁 Fix files reverted (1 files)
  • src/Controls/src/Core/Handlers/Items2/ItemsViewHandler2.Windows.cs

📋 Pre-Flight — Context & Validation

Issue: #38059 - [.NET11] I1 - Big blank spaces between texts
PR: #38367 - [net 11] [Windows] Fix excessive spacing in untemplated CollectionView vertical grids
Platforms Affected: Windows
Files Changed: 1 implementation, 14 test

Key Findings

  • The regression starts in .NET 11 Preview 6 (Preview 5 is unaffected): an untemplated CollectionView grid with MeasureAllItems displays excessive blank space between text rows on Windows.
  • The active .NET 11 Windows CollectionView implementation is Items2. The production change is limited to src/Controls/src/Core/Handlers/Items2/ItemsViewHandler2.Windows.cs.
  • The PR attributes the spacing to UniformGridLayoutItemsStretch.Uniform, which preserves aspect ratio and inflates row height as text items widen. Its fix keeps Uniform only for horizontal grids and uses Fill for vertical grids.
  • The UI regression fixture exercises both the initial vertical two-column grid and a runtime switch to a horizontal four-row grid. Existing snapshots cover Windows and the unaffected Android, iOS, and Mac baselines.
  • Earlier inline feedback about CollectionView sharding and missing horizontal-orientation coverage is addressed in the squashed commit: both methods use ShardedTestCategory, and both orientations have screenshot assertions.
  • Gate verification already passed: Issue38059 failed without the production fix and both tests passed with it. Per instruction, gate verification must not be rerun.
  • Detected primary test command: pwsh .github/scripts/BuildAndRunHostApp.ps1 -Platform windows -TestFilter "Issue38059".
  • No additional mandatory regression test was listed for STEP 5a; no full or category-wide suite is authorized.

Code Review Summary

Verdict: SKIPPED
Confidence: N/A
Errors: 0 | Warnings: 0 | Suggestions: 0

Key code review findings:

  • Dedicated expert review is intentionally reserved for STEP 5b. This pre-flight inspected context and the diff only, as required.

Fix Candidates

# Source Approach Test Result Files Changed Notes
PR PR #38367 Make ItemsStretch orientation-aware: retain Uniform for untemplated horizontal MeasureAllItems grids and use Fill otherwise ✅ PASSED (Gate) ItemsViewHandler2.Windows.cs Original PR

🔬 Code Review — Deep Analysis

Code Review — PR #38367

Independent Assessment

What this changes: The Windows CollectionView2 handler now uses UniformGridLayoutItemsStretch.Fill for untemplated, MeasureAllItems vertical grids while preserving Uniform stretching for the corresponding horizontal-grid case. The added UI test captures both orientations so the vertical spacing fix and the horizontal scrolling behavior are regression-covered.

Inferred motivation: WinUI's Uniform stretch mode couples the item's cross-axis growth to its scroll-axis size. In a vertical grid, widening untemplated text items therefore inflates their row heights and creates the reported gaps; Fill stretches only across the available column width while retaining natural row height.

Findings

The expert reviewer wrote an empty inline-findings.json array. No correctness, lifecycle, performance, API, or test-quality defect was identified on an added or modified line.

Blast Radius and Failure-Mode Probing

  • Runs for all instances: No. The behavior change is limited to Windows CollectionView2 grid layouts that previously selected Uniform because they had no ItemTemplate and used MeasureAllItems; templated grids, MeasureFirstItem, linear layouts, legacy Windows CollectionView, and other platforms retain their existing implementation.
  • Adjacent horizontal scenario: Horizontal grids retain Uniform, avoiding a regression in horizontal content extent; the second screenshot test exercises a runtime orientation change to this path.
  • Handler reconnect/default state: No state, subscription, mapper, or lifecycle behavior changes. The layout decision is recomputed whenever the native layout is created.
  • Null/default values: Existing access patterns are unchanged; the new orientation predicate operates on the already-required GridItemsLayout.

External Output Contract

Not applicable.

Verdict: LGTM

Confidence: medium — the change is localized and regression-covered, but it alters Windows-specific native layout plumbing, which caps confidence at medium.
Summary: The orientation-specific stretch selection addresses the vertical-grid failure mechanism without broadening behavior changes to adjacent CollectionView modes. The submitted test covers both the fixed vertical case and the preserved horizontal case, and the trusted Gate confirms it fails without the fix and passes with it.


🛠️ Try-Fix — Analysis & Comparison

Fix Candidates

# Source Approach Test Result Files Changed Notes
1 gpt-5.3-codex / try-fix Post-measure normalization of realized item extent while preserving WinUI stretch selection ⚠️ BLOCKED 0 files Baseline guard rejected unrelated dirty tracked files; the observed 2/2 pass exercised the PR fix, not this unimplemented candidate
2 gpt-5.6-sol / try-fix Set cross-axis minimum cell geometry from viewport and Span before realization while retaining Uniform ⚠️ BLOCKED 0 files Same baseline guard; test correctly skipped because unchanged PR code would not validate the candidate
PR PR #38367 Retain Uniform only for horizontal, untemplated MeasureAllItems grids; use Fill otherwise ✅ PASSED (Gate) 1 implementation file Gate failed without fix and passed both orientation screenshots with fix

Candidate 1 Narrative

Candidate 1 proposed correcting realized item extent after WinUI layout rather than changing ItemsStretch. It could not implement that mechanism: EstablishBrokenBaseline.ps1 refused to create the required restore allow-list because unrelated tracked harness files were already dirty. No source diff exists. The required UI command passed 2/2 only against the restored PR code and therefore supplies no evidence for the candidate.

Candidate 2 Narrative

Candidate 2 proposed retaining Uniform while supplying UniformGridLayout with a cross-axis minimum cell size derived from the live viewport and Span before realization, recomputing the constraint on resize and orientation changes. Unlike the PR, it would not switch stretch algorithms; unlike candidate 1, it would not rewrite realized geometry after measurement. The same baseline safety guard blocked implementation before edits. The UI command was intentionally skipped because it could only exercise unchanged PR code, so this candidate is also unvalidated and has no source diff.

Cross-Pollination

Skipped by the STEP 5a hard execution contract.

Exhausted: Yes — both authorized model attempts completed; no additional agents, cross-pollination, or correction rounds are permitted.
Selected Fix: PR #38367's fix — it is the only implementation with causal gate evidence (failure without the fix and 2/2 passing with it). Both alternatives were blocked before implementation and cannot be ranked as viable fixes.


🏁 Report — Final Recommendation

✅ Final Recommendation: APPROVE

Winner: pr

The submitted PR is the single winning candidate. It makes the narrow Windows CollectionView2 change that directly addresses the failure mechanism, preserves the adjacent untemplated horizontal-grid behavior, and is the only implemented approach backed by causal regression evidence: the vertical screenshot test failed without the production change, then both vertical and horizontal tests passed with it. The expert reviewer found no blocking errors, warnings, or discussion items, and the regression cross-reference reported no overlap with recent bug fixes.

Comparative Ranking

Rank Candidate Implementation Regression evidence Expert assessment Result
1 pr Uses Fill for the affected untemplated MeasureAllItems vertical grid while retaining Uniform for horizontal flow ✅ Trusted Gate: vertical test failed without fix; 2/2 orientation tests passed with fix ✅ No findings Winner
2 pr-plus-reviewer Byte-for-byte equivalent to pr; reviewer supplied no actionable refinement ✅ Same submitted implementation and Gate evidence; no redundant candidate run ✅ No findings; empty reviewer.patch Sound, but adds no improvement over pr
3 try-fix-1 Proposed post-measure normalization of realized item extent ⚠️ Blocked before implementation; its 2/2 run exercised the PR code, not the proposed candidate No candidate diff to review Non-viable
4 try-fix-2 Proposed viewport-derived cross-axis minimum cell geometry while retaining Uniform ⚠️ Blocked before implementation; validation correctly skipped No candidate diff to review Non-viable

Why the PR Wins

  • Correct scope: The predicate changes only the Windows CollectionView2 grid case that previously selected Uniform; templated layouts, MeasureFirstItem, linear layouts, the legacy handler, and other platforms are untouched.
  • Adjacent behavior preserved: Horizontal untemplated grids continue using Uniform, and the test switches orientation at runtime to exercise that path.
  • Strongest evidence: The Gate isolates the implementation line as causal rather than merely showing a green test on the fixed tree.
  • No beneficial refinement exists: The one permitted expert pass produced [], so selecting pr-plus-reviewer would request changes for an empty patch.

Confidence: Medium. The implementation and regression evidence are strong, while the confidence ceiling reflects that this is Windows-specific native layout behavior.


📱 UI Tests — CollectionView

Detected UI test categories: CollectionView

[!WARNING]
No UI test results were produced for the detected categories. The PR build itself was
fine — the deep UI stage was skipped or interrupted on infrastructure (the
merge-for-testing step, emulator/simulator boot, or an Appium hang), not by this PR's code.
This is usually transient; the review re-runs on new commits (a maintainer can also re-run it).


🧭 Next Steps — review latest findings

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

@MauiBot MauiBot added s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix) and removed s/agent-review-in-progress AI review is currently running for this PR labels Oct 1, 2026
@kubaflo

This comment has been minimized.

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Tests Failure Analysis

@Shalini-Ashokan — test-failure analysis for commit bba199f.

Scope CI failures Commit bba199f


🧪 CI Analysis — click to expand
📊 maui-pr
  • 🟢 Likely unrelated — WorkloadInstallPathsAreIndependentOfTrailingSeparator (Windows, macOS): missing SDK directory matches net11.0; SDK/setup unchanged.

🧪 maui-pr-devicetests

🧪 maui-pr-uitests

Target history is partial.


🧭 Follow-up — actions and refresh

Next action: Recover diagnostics; reproduce unresolved failures on net11.0 with identical setup.

Maintainers: comment /review tests to refresh this report.

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>
@sheiksyedm
sheiksyedm marked this pull request as ready for review October 7, 2026 10:27
Copilot AI balanced review requested due to automatic review settings October 7, 2026 10:27
@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.

@kubaflo
kubaflo merged commit a484bde into dotnet:net11.0 Oct 7, 2026
148 of 169 checks passed
@github-actions github-actions Bot added this to the .NET 11.0-rc2 milestone Oct 7, 2026

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

🟡 Changes recommended

The horizontal grid case reported by issue #38059 remains widely spaced and is not fixed by the orientation condition.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adjusts the Windows Items2 CollectionView handler to prevent inflated row heights in untemplated vertical grids.

Changes:

  • Uses Fill stretching for vertical grids.
  • Adds vertical and horizontal screenshot tests.
  • Adds platform-specific visual baselines.
File Description
src/​Controls/​src/​Core/​Handlers/​Items2/​ItemsViewHandler2.Windows.cs Changes grid stretching behavior.
src/​Controls/​tests/​TestCases.HostApp/​Issues/​Issue38059.cs Adds the regression test page.
src/​Controls/​tests/​TestCases.Shared.Tests/​Tests/​Issues/​Issue38059.cs Adds screenshot tests.
src/​Controls/​tests/​TestCases.Android.Tests/​snapshots/​android/​Issue38059_UntemplatedVerticalGridLayout.png Android vertical baseline.
src/​Controls/​tests/​TestCases.Android.Tests/​snapshots/​android/​Issue38059_UntemplatedHorizontalGridLayout.png Android horizontal baseline.
src/​Controls/​tests/​TestCases.iOS.Tests/​snapshots/​ios/​Issue38059_UntemplatedVerticalGridLayout.png iOS vertical baseline.
src/​Controls/​tests/​TestCases.iOS.Tests/​snapshots/​ios/​Issue38059_UntemplatedHorizontalGridLayout.png iOS horizontal baseline.
src/​Controls/​tests/​TestCases.iOS.Tests/​snapshots/​ios-26/​Issue38059_UntemplatedVerticalGridLayout.png iOS 26 vertical baseline.
src/​Controls/​tests/​TestCases.iOS.Tests/​snapshots/​ios-26/​Issue38059_UntemplatedHorizontalGridLayout.png iOS 26 horizontal baseline.
src/​Controls/​tests/​TestCases.Mac.Tests/​snapshots/​mac/​Issue38059_UntemplatedVerticalGridLayout.png MacCatalyst vertical baseline.
src/​Controls/​tests/​TestCases.Mac.Tests/​snapshots/​mac/​Issue38059_UntemplatedHorizontalGridLayout.png MacCatalyst horizontal baseline.
src/​Controls/​tests/​TestCases.WinUI.Tests/​snapshots/​windows/​Issue38059_UntemplatedVerticalGridLayout.png Windows CV2 vertical baseline.
src/​Controls/​tests/​TestCases.WinUI.Tests/​snapshots/​windows/​Issue38059_UntemplatedHorizontalGridLayout.png Windows CV2 horizontal baseline.
src/​Controls/​tests/​TestCases.WinUI.Tests/​snapshots/​windows-cv1/​Issue38059_UntemplatedVerticalGridLayout.png Windows CV1 vertical baseline.
src/​Controls/​tests/​TestCases.WinUI.Tests/​snapshots/​windows-cv1/​Issue38059_UntemplatedHorizontalGridLayout.png Windows CV1 horizontal baseline.

bool isHorizontalLayout = gridItemsLayout.Orientation == ItemsLayoutOrientation.Horizontal;
// Uniform stretching gives an untemplated horizontal grid enough width to scroll,
// but on a vertical grid it also inflates row height and creates large blank gaps.
layout.ItemsStretch = (isHorizontalLayout && noTemplate && isMeasureAllItems)
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 Nov 7, 2026
@github-actions github-actions Bot modified the milestones: .NET 11.0-rc2, .NET 11.0 GA Nov 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-controls-collectionview CollectionView, CarouselView, IndicatorView collectionview-winui-cv2 community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/windows s/agent-approved AI agent recommends approval - PR fix is correct and optimal s/agent-fix-pr-picked AI could not beat the PR fix - PR is the best among all candidates s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix) 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.

7 participants