Skip to content

Fixed HorizontalStackLayout Crashes Debugger on Negative Spacing#26927

Merged
StephaneDelcroix merged 4 commits intodotnet:inflight/currentfrom
devanathan-vaithiyanathan:fix-19513
Dec 3, 2025
Merged

Fixed HorizontalStackLayout Crashes Debugger on Negative Spacing#26927
StephaneDelcroix merged 4 commits intodotnet:inflight/currentfrom
devanathan-vaithiyanathan:fix-19513

Conversation

@devanathan-vaithiyanathan
Copy link
Contributor

@devanathan-vaithiyanathan devanathan-vaithiyanathan commented Jan 2, 2025

Issue Details:

When negative spacing value is given for StackLayout, System.ArgumentOutOfRangeException is thrown in WinUI.

The issue occurs when an Image control is placed inside a StackLayout without explicitly setting the HeightRequest and WidthRequest properties.

Root Cause:

The measured value (Width/Height)of the elements like image has calculated as 0 during first measure call in WinUI platform when negative spacing is passed for Layouts. When deducting the negative spacing from measured value(Width / height) in Measure() of LayoutManager.cs it will return negative value in Measure override of MauiPanel.cs. So when converting this negative value to ToPlatform(), System.ArgumentOutOfRangeException is thrown.

Description of Change:

As Measured value of Image is negative during first call from native, the negative value has been constrained and the measured value is set to 0 using Math.Max() and converting 0 to ToPlatform() will not throw exception.
On the subsequent call, the Image is measured correctly, and the negative spacing is appropriately deducted from the measured value. This adjustment ensures that the spacing is applied accurately and aligns with the intended layout behavior.

Issues Fixed

Fixes #19513

Tested the behavior in the following platforms.

  • Android
  • Windows
  • iOS
  • Mac

#Output Screenshot

Before After

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Jan 2, 2025
@dotnet-policy-service
Copy link
Contributor

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

@karthikraja-arumugam karthikraja-arumugam added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Jan 3, 2025
@devanathan-vaithiyanathan devanathan-vaithiyanathan marked this pull request as ready for review January 3, 2025 14:11
@devanathan-vaithiyanathan devanathan-vaithiyanathan requested a review from a team as a code owner January 3, 2025 14:11
@rmarinho
Copy link
Member

rmarinho commented Jan 7, 2025

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@jfversluis jfversluis added the area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter label Jan 9, 2025
@mattleibow
Copy link
Member

/rebase

@StephaneDelcroix StephaneDelcroix changed the base branch from main to inflight/current December 3, 2025 13:23
@StephaneDelcroix StephaneDelcroix merged commit f7ffadf into dotnet:inflight/current Dec 3, 2025
1 of 2 checks passed
PureWeen pushed a commit that referenced this pull request Dec 3, 2025
)

* Fixed HorizontalStackLayout Crashes Debugger on Negative Spacing

* Reverted changes in CrossPlatformMeasure

* Revert "Reverted changes in CrossPlatformMeasure"

This reverts commit 4d53baf.

* Reverted changes in ArrangeOverride

---------

Co-authored-by: Dhivya-SF4094 <127717131+Dhivya-SF4094@users.noreply.github.com>
PureWeen pushed a commit that referenced this pull request Dec 3, 2025
)

* Fixed HorizontalStackLayout Crashes Debugger on Negative Spacing

* Reverted changes in CrossPlatformMeasure

* Revert "Reverted changes in CrossPlatformMeasure"

This reverts commit 4d53baf.

* Reverted changes in ArrangeOverride

---------

Co-authored-by: Dhivya-SF4094 <127717131+Dhivya-SF4094@users.noreply.github.com>
PureWeen pushed a commit that referenced this pull request Dec 3, 2025
)

* Fixed HorizontalStackLayout Crashes Debugger on Negative Spacing

* Reverted changes in CrossPlatformMeasure

* Revert "Reverted changes in CrossPlatformMeasure"

This reverts commit 4d53baf.

* Reverted changes in ArrangeOverride

---------

Co-authored-by: Dhivya-SF4094 <127717131+Dhivya-SF4094@users.noreply.github.com>
PureWeen pushed a commit that referenced this pull request Dec 3, 2025
)

* Fixed HorizontalStackLayout Crashes Debugger on Negative Spacing

* Reverted changes in CrossPlatformMeasure

* Revert "Reverted changes in CrossPlatformMeasure"

This reverts commit 4d53baf.

* Reverted changes in ArrangeOverride

---------

Co-authored-by: Dhivya-SF4094 <127717131+Dhivya-SF4094@users.noreply.github.com>
PureWeen pushed a commit that referenced this pull request Dec 3, 2025
)

* Fixed HorizontalStackLayout Crashes Debugger on Negative Spacing

* Reverted changes in CrossPlatformMeasure

* Revert "Reverted changes in CrossPlatformMeasure"

This reverts commit 4d53baf.

* Reverted changes in ArrangeOverride

---------

Co-authored-by: Dhivya-SF4094 <127717131+Dhivya-SF4094@users.noreply.github.com>
github-actions bot pushed a commit that referenced this pull request Dec 5, 2025
)

* Fixed HorizontalStackLayout Crashes Debugger on Negative Spacing

* Reverted changes in CrossPlatformMeasure

* Revert "Reverted changes in CrossPlatformMeasure"

This reverts commit 4d53baf.

* Reverted changes in ArrangeOverride

---------

Co-authored-by: Dhivya-SF4094 <127717131+Dhivya-SF4094@users.noreply.github.com>
@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/windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HorizontalStackLayout Crashes Debugger on Negative Spacing

8 participants