diff --git a/src/Avalonia.Controls/StackPanel.cs b/src/Avalonia.Controls/StackPanel.cs index 6caffb8686..0a64096ee9 100644 --- a/src/Avalonia.Controls/StackPanel.cs +++ b/src/Avalonia.Controls/StackPanel.cs @@ -215,13 +215,13 @@ namespace Avalonia.Controls } } - if (Orientation == Orientation.Vertical) + if (fHorizontal) { - stackDesiredSize = stackDesiredSize.WithHeight(stackDesiredSize.Height - (hasVisibleChild ? spacing : 0)); + stackDesiredSize = stackDesiredSize.WithWidth(stackDesiredSize.Width - (hasVisibleChild ? spacing : 0)); } else - { - stackDesiredSize = stackDesiredSize.WithWidth(stackDesiredSize.Width - (hasVisibleChild ? spacing : 0)); + { + stackDesiredSize = stackDesiredSize.WithHeight(stackDesiredSize.Height - (hasVisibleChild ? spacing : 0)); } return stackDesiredSize; @@ -252,16 +252,16 @@ namespace Avalonia.Controls if (fHorizontal) { rcChild = rcChild.WithX(rcChild.X + previousChildSize); - previousChildSize = child.DesiredSize.Width; + previousChildSize = child.DesiredSize.Width + (child.IsVisible ? spacing : 0); rcChild = rcChild.WithWidth(previousChildSize); - rcChild = rcChild.WithHeight(Math.Max(finalSize.Height, child.DesiredSize.Height) + (child.IsVisible ? spacing : 0)); + rcChild = rcChild.WithHeight(Math.Max(finalSize.Height, child.DesiredSize.Height)); } else { rcChild = rcChild.WithY(rcChild.Y + previousChildSize); - previousChildSize = child.DesiredSize.Height; + previousChildSize = child.DesiredSize.Height + (child.IsVisible ? spacing : 0); rcChild = rcChild.WithHeight(previousChildSize); - rcChild = rcChild.WithWidth(Math.Max(finalSize.Width, child.DesiredSize.Width) + (child.IsVisible ? spacing : 0)); + rcChild = rcChild.WithWidth(Math.Max(finalSize.Width, child.DesiredSize.Width)); } child.Arrange(rcChild);