Skip to content

[Windows] Fixed ItemSpacing doesn't work in Carousel View#30014

Merged
kubaflo merged 11 commits intodotnet:inflight/currentfrom
SubhikshaSf4851:fix-29772
Apr 10, 2026
Merged

[Windows] Fixed ItemSpacing doesn't work in Carousel View#30014
kubaflo merged 11 commits intodotnet:inflight/currentfrom
SubhikshaSf4851:fix-29772

Conversation

@SubhikshaSf4851
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!

Root Cause:

CarouselView does not utilize the ItemSpacing property during layout styling

Description of Change

Added an item container style based on the horizontal or vertical orientation of the CarouselView, and applied a corresponding style to the ListViewBase

Issues Fixed

Fixes #29772

Tested the behaviour in the following platforms

  • Windows
  • Android
  • iOS
  • Mac

Screenshot

Before Issue Fix After Issue Fix

@dotnet-policy-service dotnet-policy-service Bot added community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration labels Jun 16, 2025
@jsuarezruiz jsuarezruiz added platform/windows area-controls-collectionview CollectionView, CarouselView, IndicatorView labels Jun 17, 2025
@jsuarezruiz
Copy link
Copy Markdown
Contributor

/azp run MAUI-UITests-public

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@jsuarezruiz
Copy link
Copy Markdown
Contributor

/azp run MAUI-UITests-public

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@SubhikshaSf4851 SubhikshaSf4851 marked this pull request as ready for review June 20, 2025 14:36
Copilot AI review requested due to automatic review settings June 20, 2025 14:36
@SubhikshaSf4851 SubhikshaSf4851 requested a review from a team as a code owner June 20, 2025 14:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enables ItemSpacing for CarouselView on Windows by applying an ItemContainerStyle and adjusting item size calculations, and adds a UI test to verify the fix.

  • Added a host app page and shared UI test for Issue 29772
  • Updated CarouselViewHandler.Windows to set container padding and account for ItemSpacing when measuring items

Reviewed Changes

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

File Description
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29772.cs Added a UI test for ItemSpacing but gated to iOS/Catalyst only
src/Controls/tests/TestCases.HostApp/Issues/Issue29772.cs Host app page with a CarouselView setup, binding, and automation ID for testing ItemSpacing
src/Controls/src/Core/Handlers/Items/CarouselViewHandler.Windows.cs Applied ItemContainerStyle and updated GetItemWidth/GetItemHeight to subtract spacing

Comment thread src/Controls/src/Core/Handlers/Items/CarouselViewHandler.Windows.cs Outdated
Comment thread src/Controls/src/Core/Handlers/Items/CarouselViewHandler.Windows.cs Outdated
Comment thread src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29772.cs Outdated
@MauiBot
Copy link
Copy Markdown
Collaborator

MauiBot commented Mar 21, 2026

🤖 AI Summary

📊 Expand Full Reviewb692a87 · Implemented the suggested approach
🔍 Pre-Flight — Context & Validation

Issue: #29772 - ItemSpacing on CarouselView is not applied on Windows.
PR: #30014 - [Windows] Fixed ItemSpacing doesn't work in Carousel View
Platforms Affected: Windows (primary); Android/iOS/Mac also tested by author
Files Changed: 1 implementation, 2 test (+ 5 snapshot PNG files)

Key Findings

  • LinearItemsLayout.ItemSpacing was being ignored on Windows in CarouselViewHandler; spacing was never applied to WinUI ListViewItem containers
  • Fix approach: (1) New GetItemContainerStyle() creates a WStyle for ListViewItem with Control.PaddingProperty set to half-spacing on each side; (2) GetItemWidth()/GetItemHeight() unconditionally subtract ItemSpacing from item dimensions when orientation matches
  • Current branch (b692a87) vs prior review commit (2ed72f7): The prior agent review (REQUEST CHANGES) flagged that ItemSpacing subtraction was gated on PeekAreaInsets > 0. That gate has been removed in the current branch — subtraction is now unconditional for matching orientation
  • Dynamic update gap: GetItemContainerStyle() is called once at list creation; no mapper to re-apply style when ItemSpacing changes at runtime
  • PlatformAffected.UWP in HostApp: [Issue(IssueTracker.Github, 29772, "...", PlatformAffected.UWP)] — should be PlatformAffected.All (cosmetic)
  • CarouselViewShouldRenderCorrectly.png modified: An existing unrelated Windows snapshot was changed; PR description does not explain why
  • Test uses VerifyScreenshot() with no [Platform] filter — runs on all platforms; Windows snapshot present
  • Gate result: ✅ PASSED — tests FAIL without fix, PASS with fix (per task context)
  • Prior agent review: s/agent-changes-requested + s/agent-fix-win were applied; PR has since been updated to address P1 issue

Fix Candidates

# Source Approach Test Result Files Changed Notes
PR PR #30014 Add ItemContainerStyle with half-spacing padding on ListViewItem; unconditionally subtract ItemSpacing from item dimensions ✅ PASSED (Gate) CarouselViewHandler.Windows.cs P1 (gate) issue from prior review now fixed; dynamic update and UWP label remain

🔧 Fix — Analysis & Comparison

Fix Candidates

# Source Approach Test Result Files Changed Notes
1 try-fix (claude-opus-4.6) Margin-based spacing: FrameworkElement.MarginProperty on ListViewItem with BasedOn style inheritance; unconditional ItemSpacing subtraction in GetItemWidth/GetItemHeight ✅ Pass 1 file Margin creates gaps outside container; better semantic match for spacing between items
2 try-fix (claude-sonnet-4.6) ItemContentControl.Margin via PropertyChangedCallback on existing ItemSpacingProperty; symmetric GetItemSpacing(); unconditional subtraction in GetItemWidth/GetItemHeight ✅ Pass 2 files Activates existing data-binding infrastructure; no ItemContainerStyle at all
3 try-fix (gpt-5.3-codex) ContainerContentChanging event handler to apply asymmetric ListViewItem.Padding per container ❌ Fail 1 file 5.22% visual diff — asymmetric padding produced inconsistent rendering
4 try-fix (gpt-5.4) Runtime UpdateItemSpacing() method subscribed to LinearItemsLayout.ItemSpacing changes; reapplies Control.PaddingProperty style + invalidates item sizes dynamically ✅ Pass 1 file Adds dynamic update support missing from PR; most complete solution
PR PR #30014 Control.PaddingProperty on ListViewItem via ItemContainerStyle; unconditional ItemSpacing subtraction ✅ PASSED (Gate) 1 file P1 gate issue from prior review addressed

Cross-Pollination

Model Round New Ideas? Details
claude-opus-4.6 2 No ItemsStackPanel has no Spacing property; panel-level approach not viable
gpt-5.4 2 No Agrees viable approaches exhausted

Exhausted: Yes
Selected Fix: PR's fix — Gate ✅ PASSED; P1 issue (PeekAreaInsets gate) addressed; approach is valid. Attempt 4 shows a dynamic update path is feasible, but that is a P2 enhancement. Recommend PR approval with minor required changes.


📋 Report — Final Recommendation

✅ Final Recommendation: APPROVE

Phase Status

Phase Status Notes
Pre-Flight ✅ COMPLETE Issue #29772 — Windows CarouselView ItemSpacing ignored
Gate ✅ PASSED windows — tests FAIL without fix, PASS with fix
Try-Fix ✅ COMPLETE 4 attempts: 3 passing, 1 failing; cross-pollination exhausted
Report ✅ COMPLETE

Summary

The PR fixes ItemSpacing not being applied on Windows CarouselView. The root cause is correctly identified and the fix approach is valid. The primary concern from the prior agent review (spacing subtraction gated on PeekAreaInsets > 0) has been addressed in the updated PR — the subtraction is now unconditional for matching orientation. All try-fix alternatives passed confirm this is a viable fix space; the PR's approach is the simplest and most focused.

Root Cause

CarouselViewHandler.CreateCarouselListLayout() never applied any padding or margin to ListViewItem containers, so ItemSpacing had no visual effect on Windows. The existing GetItemSpacing() method was unused for container styling.

Fix Quality

What the PR does right:

  • GetItemContainerStyle() correctly uses Control.PaddingProperty on ListViewItem with half-spacing per side, creating the visual gap
  • GetItemWidth()/GetItemHeight() now unconditionally subtract ItemSpacing when orientation matches — the P1 gate issue from the prior review is fixed
  • ItemContainerStyle applied at list creation for both horizontal and vertical orientations
  • UI test with Windows snapshot present; gate confirms it validates the fix

Minor issues (non-blocking):

  1. GetItemContainerStyle() only called at list creation (P2): If ItemSpacing changes at runtime, the ItemContainerStyle won't update. Try-Fix attempt 4 showed a dynamic subscription approach is feasible. This is an acceptable known limitation for this PR scope.
  2. PlatformAffected.UWP in HostApp (P3 — cosmetic): [Issue(IssueTracker.Github, 29772, "...", PlatformAffected.UWP)] — modern MAUI uses PlatformAffected.All for Windows. Cosmetic only.
  3. CarouselViewShouldRenderCorrectly.png modified (P2): An existing unrelated Windows snapshot changed; PR description doesn't explain why. Should be verified to confirm the fix didn't regress the existing test.

Try-Fix Comparison

Approach Files Result Notes
PR's fix 1 ✅ Gate Control.PaddingProperty + unconditional subtraction
Margin-based (attempt 1) 1 ✅ Pass FrameworkElement.MarginProperty — semantically different
ItemContentControl callback (attempt 2) 2 ✅ Pass Activates existing binding chain
Asymmetric padding (attempt 3) 1 ❌ Fail 5.22% visual diff
Dynamic update (attempt 4) 1 ✅ Pass Adds runtime reactivity

Selected Fix: PR's fix — simplest single-file change, gate validated, P1 correctness issue resolved.


@MauiBot MauiBot added s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-fix-win AI found a better alternative fix than the PR s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review) labels Mar 21, 2026
Copy link
Copy Markdown
Contributor

@kubaflo kubaflo left a comment

Choose a reason for hiding this comment

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

Could you please review the AI's summary?

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 23, 2026

🚀 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://github.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 30014

Or

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

@MauiBot MauiBot added s/agent-review-incomplete AI agent could not complete all phases (blocker, timeout, error) and removed s/agent-changes-requested AI agent recommends changes - found a better alternative or issues labels Mar 24, 2026
Copy link
Copy Markdown
Contributor

@kubaflo kubaflo left a comment

Choose a reason for hiding this comment

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

The test is passing without a fix

@SubhikshaSf4851
Copy link
Copy Markdown
Contributor Author

@kubaflo The gate-without-fix check passed incorrectly because old baseline snapshots used a red background, masking the ItemSpacing difference.

Now the baselines have been updated to green background. With corrected snapshots, the test will now fail without the fix

@MauiBot MauiBot added s/agent-review-incomplete AI agent could not complete all phases (blocker, timeout, error) and removed s/agent-changes-requested AI agent recommends changes - found a better alternative or issues labels Mar 30, 2026
@kubaflo
Copy link
Copy Markdown
Contributor

kubaflo commented Mar 30, 2026

/azp run maui-pr-uitests

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@MauiBot MauiBot added s/agent-changes-requested AI agent recommends changes - found a better alternative or issues and removed s/agent-review-incomplete AI agent could not complete all phases (blocker, timeout, error) labels Mar 31, 2026
Copy link
Copy Markdown
Contributor

@kubaflo kubaflo left a comment

Choose a reason for hiding this comment

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

Could you please try:
Selected Fix: Attempt 4 approach — keep PR's Control.PaddingProperty ItemContainerStyle, remove PeekAreaInsets gate from GetItemWidth/GetItemHeight. Simplest, least invasive change that is provably correct.

@SubhikshaSf4851
Copy link
Copy Markdown
Contributor Author

@kubaflo I have implemented the suggested approach

@MauiBot MauiBot added 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 and removed s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-fix-win AI found a better alternative fix than the PR labels Apr 7, 2026
@sheiksyedm
Copy link
Copy Markdown
Contributor

/azp run maui-pr-uitests

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@kubaflo kubaflo added the s/agent-fix-implemented PR author implemented the agent suggested fix label Apr 10, 2026
@kubaflo kubaflo changed the base branch from main to inflight/current April 10, 2026 18:10
@kubaflo kubaflo merged commit 1ef6c12 into dotnet:inflight/current Apr 10, 2026
82 of 88 checks passed
PureWeen pushed a commit that referenced this pull request Apr 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!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->
### Root Cause: 
CarouselView does not utilize the ItemSpacing property during layout
styling
### Description of Change
Added an item container style based on the horizontal or vertical
orientation of the CarouselView, and applied a corresponding style to
the ListViewBase
<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #29772 
### Tested the behaviour in the following platforms

- [x] Windows
- [x] Android
- [x] iOS
- [x] Mac

### Screenshot

| Before Issue Fix | After Issue Fix |
|----------|----------|
| <img
src="https://github.com/user-attachments/assets/4af88696-c5a6-4683-bceb-1933781368f3">
| <img
src="https://github.com/user-attachments/assets/f55c2b45-22c3-4ab2-aae5-c668adaf33e4">
|
<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
devanathan-vaithiyanathan pushed a commit to Tamilarasan-Paranthaman/maui that referenced this pull request Apr 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!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->
### Root Cause: 
CarouselView does not utilize the ItemSpacing property during layout
styling
### Description of Change
Added an item container style based on the horizontal or vertical
orientation of the CarouselView, and applied a corresponding style to
the ListViewBase
<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes dotnet#29772 
### Tested the behaviour in the following platforms

- [x] Windows
- [x] Android
- [x] iOS
- [x] Mac

### Screenshot

| Before Issue Fix | After Issue Fix |
|----------|----------|
| <img
src="https://github.com/user-attachments/assets/4af88696-c5a6-4683-bceb-1933781368f3">
| <img
src="https://github.com/user-attachments/assets/f55c2b45-22c3-4ab2-aae5-c668adaf33e4">
|
<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
PureWeen pushed a commit that referenced this pull request Apr 22, 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!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->
### Root Cause: 
CarouselView does not utilize the ItemSpacing property during layout
styling
### Description of Change
Added an item container style based on the horizontal or vertical
orientation of the CarouselView, and applied a corresponding style to
the ListViewBase
<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #29772 
### Tested the behaviour in the following platforms

- [x] Windows
- [x] Android
- [x] iOS
- [x] Mac

### Screenshot

| Before Issue Fix | After Issue Fix |
|----------|----------|
| <img
src="https://github.com/user-attachments/assets/4af88696-c5a6-4683-bceb-1933781368f3">
| <img
src="https://github.com/user-attachments/assets/f55c2b45-22c3-4ab2-aae5-c668adaf33e4">
|
<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
PureWeen pushed a commit that referenced this pull request Apr 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!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->
### Root Cause: 
CarouselView does not utilize the ItemSpacing property during layout
styling
### Description of Change
Added an item container style based on the horizontal or vertical
orientation of the CarouselView, and applied a corresponding style to
the ListViewBase
<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #29772 
### Tested the behaviour in the following platforms

- [x] Windows
- [x] Android
- [x] iOS
- [x] Mac

### Screenshot

| Before Issue Fix | After Issue Fix |
|----------|----------|
| <img
src="https://github.com/user-attachments/assets/4af88696-c5a6-4683-bceb-1933781368f3">
| <img
src="https://github.com/user-attachments/assets/f55c2b45-22c3-4ab2-aae5-c668adaf33e4">
|
<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
PureWeen pushed a commit that referenced this pull request Apr 29, 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!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->
### Root Cause: 
CarouselView does not utilize the ItemSpacing property during layout
styling
### Description of Change
Added an item container style based on the horizontal or vertical
orientation of the CarouselView, and applied a corresponding style to
the ListViewBase
<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #29772 
### Tested the behaviour in the following platforms

- [x] Windows
- [x] Android
- [x] iOS
- [x] Mac

### Screenshot

| Before Issue Fix | After Issue Fix |
|----------|----------|
| <img
src="https://github.com/user-attachments/assets/4af88696-c5a6-4683-bceb-1933781368f3">
| <img
src="https://github.com/user-attachments/assets/f55c2b45-22c3-4ab2-aae5-c668adaf33e4">
|
<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-controls-collectionview CollectionView, CarouselView, IndicatorView community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/windows s/agent-approved AI agent recommends approval - PR fix is correct and optimal s/agent-fix-implemented PR author implemented the agent suggested fix 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.

ItemSpacing on CarouselView is not applied on Windows.

8 participants