Fixed HorizontalStackLayout Crashes Debugger on Negative Spacing#26927
Merged
StephaneDelcroix merged 4 commits intodotnet:inflight/currentfrom Dec 3, 2025
Merged
Conversation
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. |
MartyIX
reviewed
Jan 2, 2025
Member
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
Member
|
/rebase |
StephaneDelcroix
approved these changes
Dec 3, 2025
f7ffadf
into
dotnet:inflight/current
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
#Output Screenshot