Skip to content

Fixed Button rendering overflow in StackLayout#28001

Merged
StephaneDelcroix merged 6 commits intodotnet:inflight/currentfrom
Dhivya-SF4094:fix-22075
Dec 3, 2025
Merged

Fixed Button rendering overflow in StackLayout#28001
StephaneDelcroix merged 6 commits intodotnet:inflight/currentfrom
Dhivya-SF4094:fix-22075

Conversation

@Dhivya-SF4094
Copy link
Contributor

@Dhivya-SF4094 Dhivya-SF4094 commented Feb 24, 2025

Issue Details

When a button is placed within a stack layout and a padding of 15 is applied, the button's rendering extends beyond the boundaries of the stack layout. This results in an undesirable visual overflow.

Also, when a HeightRequest and WidthRequest are provided, the StackLayout does not adhere to the specified HeightRequest in WinUI. Instead, it adjusts based on the child's height which is unexpected.

Root Cause

In the VerticalStackLayoutManager.cs, the actual value returned from ArrangeChildren() includes padding only for the top, while the calculated value does not account for the left, right and bottom padding. This discrepancy results in button overflow within the StackLayout.

Description of Change

Implemented a fix that ensures the bounds.Width and bounds.Height values are returned, properly accounting for the right and bottom padding in the layout calculation. This update accurately incorporates all padding values, resolving the overflow issue effectively.

Validated the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Issues Fixed:

Fixes #22075
Fixes #29826

Screenshots

Before  After 
   

@dotnet-policy-service dotnet-policy-service bot added community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration labels Feb 24, 2025
@jsuarezruiz jsuarezruiz added the area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter label Feb 24, 2025
@jsuarezruiz
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@jsuarezruiz
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@Dhivya-SF4094 Dhivya-SF4094 marked this pull request as ready for review February 25, 2025 14:19
Copilot AI review requested due to automatic review settings February 25, 2025 14:19
@Dhivya-SF4094 Dhivya-SF4094 requested a review from a team as a code owner February 25, 2025 14:19
Copy link
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.

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

src/Core/src/Layouts/VerticalStackLayoutManager.cs:67

  • Replacing the calculated stack height with bounds.Height may resolve the overflow issue, but please verify that this change does not adversely affect vertical layout scenarios where the child content size exceeds the provided bounds.
return new Size(bounds.Width, bounds.Height);

src/Core/src/Layouts/HorizontalStackLayoutManager.cs:76

  • Directly returning the bounds for horizontal layout might resolve the current issue, but please confirm that it does not introduce regressions in cases where child elements require more width than the bounds indicate.
return new Size(bounds.Width, bounds.Height);

@jsuarezruiz
Copy link
Contributor

/rebase

@jsuarezruiz
Copy link
Contributor

/rebase

@jsuarezruiz
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@jsuarezruiz
Copy link
Contributor

/rebase

@jsuarezruiz
Copy link
Contributor

/rebase

@jsuarezruiz
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen PureWeen removed the request for review from tj-devel709 June 26, 2025 19:30
@jsuarezruiz
Copy link
Contributor

/rebase

{
StackLayout stackLayout = new StackLayout
{
Padding = 15,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can extend the sample? Extend the test to a case with asymmetric padding (e.g., Padding="15,30,20,25") and assert via geometry that the button’s rect is within the padded content box to catch regressions beyond screenshots.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jsuarezruiz Attempted to add an assertion verifying that the button’s layout rectangle remains within the padded content area. The test passes successfully on Android, iOS, and macOS; however, on Windows, the AutomationId does not work for layout validation.

@StephaneDelcroix StephaneDelcroix changed the base branch from main to inflight/current December 3, 2025 15:19
@StephaneDelcroix StephaneDelcroix merged commit e4240fb into dotnet:inflight/current Dec 3, 2025
120 of 165 checks passed
PureWeen pushed a commit that referenced this pull request Dec 3, 2025
* Fixed Button rendering overflow when padding is set in StackLayout

* Added test case

* Modified the fix, returned bounds.Width and bounds.height

* Added snapshots

* Re-added Snapshot for WinUI and macOS

* Resaved HorizontalScrollBarShouldHideOnNever
PureWeen pushed a commit that referenced this pull request Dec 3, 2025
* Fixed Button rendering overflow when padding is set in StackLayout

* Added test case

* Modified the fix, returned bounds.Width and bounds.height

* Added snapshots

* Re-added Snapshot for WinUI and macOS

* Resaved HorizontalScrollBarShouldHideOnNever
PureWeen pushed a commit that referenced this pull request Dec 3, 2025
* Fixed Button rendering overflow when padding is set in StackLayout

* Added test case

* Modified the fix, returned bounds.Width and bounds.height

* Added snapshots

* Re-added Snapshot for WinUI and macOS

* Resaved HorizontalScrollBarShouldHideOnNever
PureWeen pushed a commit that referenced this pull request Dec 3, 2025
* Fixed Button rendering overflow when padding is set in StackLayout

* Added test case

* Modified the fix, returned bounds.Width and bounds.height

* Added snapshots

* Re-added Snapshot for WinUI and macOS

* Resaved HorizontalScrollBarShouldHideOnNever
PureWeen pushed a commit that referenced this pull request Dec 3, 2025
* Fixed Button rendering overflow when padding is set in StackLayout

* Added test case

* Modified the fix, returned bounds.Width and bounds.height

* Added snapshots

* Re-added Snapshot for WinUI and macOS

* Resaved HorizontalScrollBarShouldHideOnNever
github-actions bot pushed a commit that referenced this pull request Dec 5, 2025
* Fixed Button rendering overflow when padding is set in StackLayout

* Added test case

* Modified the fix, returned bounds.Width and bounds.height

* Added snapshots

* Re-added Snapshot for WinUI and macOS

* Resaved HorizontalScrollBarShouldHideOnNever
@github-actions github-actions bot locked and limited conversation to collaborators Jan 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/android platform/ios platform/windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Windows] StackLayout does not constrain child controls when padding is added Button rendering overflow issue when padding is set in StackLayout.

5 participants