Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue29919.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 29919, "StackLayout Throws Exception on Windows When Orientation Is Set with HeightRequest of 0, Padding, and Opposing Alignment", PlatformAffected.UWP)]
public class Issue29919 : ContentPage
{
public Issue29919()
{
var stack = new StackLayout();
var label = new Label
{
Text = "VerticalStackLayout and HorizontalStackLayout should not crash when WidthRequest or HeightRequest is explicitly set to 0, respectively.",
AutomationId = "29919DescriptionLabel",
};

var horizontalStack = new HorizontalStackLayout
{
Padding = new Thickness(5),
HeightRequest = 0,
VerticalOptions = LayoutOptions.Center
};

var verticalStack = new VerticalStackLayout
{
Padding = new Thickness(5),
WidthRequest = 0,
HeightRequest = 100,
HorizontalOptions = LayoutOptions.Center
};

stack.Children.Add(label);
stack.Children.Add(horizontalStack);
stack.Children.Add(verticalStack);
Content = stack;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue29919 : _IssuesUITest
{
public Issue29919(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "StackLayout Throws Exception on Windows When Orientation Is Set with HeightRequest of 0, Padding, and Opposing Alignment";

[Test]
[Category(UITestCategories.Layout)]
public void StackLayoutWindowsCrashWithZeroHeight()
{
App.WaitForElement("29919DescriptionLabel");
}
}
2 changes: 1 addition & 1 deletion src/Core/src/Layouts/HorizontalStackLayoutManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public override Size ArrangeChildren(Rect bounds)

double top = padding.Top + bounds.Top;

var height = bounds.Height - padding.VerticalThickness;
var height = Math.Max(0, bounds.Height - padding.VerticalThickness);

// Figure out where we're starting from
double xPosition = padding.Left + bounds.Left;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/src/Layouts/VerticalStackLayoutManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public override Size ArrangeChildren(Rect bounds)

double stackHeight = padding.Top + bounds.Y;
double left = padding.Left + bounds.X;
double width = bounds.Width - padding.HorizontalThickness;
double width = Math.Max(0, bounds.Width - padding.HorizontalThickness);
Copy link

Copilot AI Jun 11, 2025

Choose a reason for hiding this comment

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

[nitpick] The clamp logic (Math.Max(0, ...)) is duplicated in both layout managers. Consider extracting a helper method (e.g., ClampNonNegative) to improve code reuse and readability.

Suggested change
double width = Math.Max(0, bounds.Width - padding.HorizontalThickness);
double width = ClampNonNegative(bounds.Width - padding.HorizontalThickness);

Copilot uses AI. Check for mistakes.

for (int n = 0; n < Stack.Count; n++)
{
Expand Down
Loading