From e329140c04fd7a0a7d555b954f6e9522c15811c6 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sat, 17 Mar 2018 23:22:01 +0100 Subject: [PATCH 1/2] Added failing test for #1447. --- .../ContentPresenterTests_Layout.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/Avalonia.Controls.UnitTests/Presenters/ContentPresenterTests_Layout.cs b/tests/Avalonia.Controls.UnitTests/Presenters/ContentPresenterTests_Layout.cs index 2ab02a0418..b3c617c4ab 100644 --- a/tests/Avalonia.Controls.UnitTests/Presenters/ContentPresenterTests_Layout.cs +++ b/tests/Avalonia.Controls.UnitTests/Presenters/ContentPresenterTests_Layout.cs @@ -80,6 +80,31 @@ namespace Avalonia.Controls.UnitTests.Presenters Assert.Equal(new Rect(expectedX, expectedY, expectedWidth, expectedHeight), content.Bounds); } + [Fact] + public void Should_Correctly_Align_Child_With_Fixed_Size() + { + Border content; + var target = new ContentPresenter + { + HorizontalContentAlignment = HorizontalAlignment.Stretch, + VerticalContentAlignment = VerticalAlignment.Stretch, + Content = content = new Border + { + HorizontalAlignment = HorizontalAlignment.Left, + VerticalAlignment = VerticalAlignment.Bottom, + Width = 16, + Height = 16, + }, + }; + + target.UpdateChild(); + target.Measure(new Size(100, 100)); + target.Arrange(new Rect(0, 0, 100, 100)); + + // Check correct result for Issue #1447. + Assert.Equal(new Rect(0, 84, 16, 16), content.Bounds); + } + [Fact] public void Content_Can_Be_Stretched() { From 0c94c82b42fd59fd105635eddea7e26d5a22d2d2 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sat, 17 Mar 2018 23:23:11 +0100 Subject: [PATCH 2/2] Don't apply layout constraints to child. The child itself will take care of applying its own layout constraints, applying them in the `ContentPresenter` arrange causes #1447. Fixes #1447. --- src/Avalonia.Controls/Presenters/ContentPresenter.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Avalonia.Controls/Presenters/ContentPresenter.cs b/src/Avalonia.Controls/Presenters/ContentPresenter.cs index d0a438cc2b..54626e9e97 100644 --- a/src/Avalonia.Controls/Presenters/ContentPresenter.cs +++ b/src/Avalonia.Controls/Presenters/ContentPresenter.cs @@ -221,7 +221,7 @@ namespace Avalonia.Controls.Presenters { var content = Content; var oldChild = Child; - var newChild = CreateChild(); + var newChild = CreateChild(); // Remove the old child if we're not recycling it. if (oldChild != null && newChild != oldChild) @@ -397,8 +397,6 @@ namespace Avalonia.Controls.Presenters size = size.WithHeight(Math.Min(size.Height, DesiredSize.Height - padding.Top - padding.Bottom)); } - size = LayoutHelper.ApplyLayoutConstraints(Child, size); - if (useLayoutRounding) { size = new Size( @@ -412,7 +410,6 @@ namespace Avalonia.Controls.Presenters switch (horizontalContentAlignment) { case HorizontalAlignment.Center: - case HorizontalAlignment.Stretch: originX += (availableSizeMinusMargins.Width - size.Width) / 2; break; case HorizontalAlignment.Right: @@ -423,7 +420,6 @@ namespace Avalonia.Controls.Presenters switch (verticalContentAlignment) { case VerticalAlignment.Center: - case VerticalAlignment.Stretch: originY += (availableSizeMinusMargins.Height - size.Height) / 2; break; case VerticalAlignment.Bottom: