浏览代码

Fix layout error.

Steven Kirk 9 年之前
父节点
当前提交
46c93b70bf
共有 2 个文件被更改,包括 19 次插入4 次删除
  1. 2 4
      src/Perspex.Layout/Layoutable.cs
  2. 17 0
      tests/Perspex.Layout.UnitTests/ArrangeTests.cs

+ 2 - 4
src/Perspex.Layout/Layoutable.cs

@@ -534,14 +534,12 @@ namespace Perspex.Layout
 
                 if (horizontalAlignment != HorizontalAlignment.Stretch)
                 {
-                    size = size.WithWidth(Math.Min(size.Width, DesiredSize.Width) 
-                        - margin.Left - margin.Right);
+                    size = size.WithWidth(Math.Min(size.Width, DesiredSize.Width - margin.Left - margin.Right));
                 }
 
                 if (verticalAlignment != VerticalAlignment.Stretch)
                 {
-                    size = size.WithHeight(Math.Min(size.Height, DesiredSize.Height)
-                        - margin.Top - margin.Bottom);
+                    size = size.WithHeight(Math.Min(size.Height, DesiredSize.Height - margin.Top - margin.Bottom));
                 }
 
                 size = LayoutHelper.ApplyLayoutConstraints(this, size);

+ 17 - 0
tests/Perspex.Layout.UnitTests/ArrangeTests.cs

@@ -58,6 +58,23 @@ namespace Perspex.Layout.UnitTests
             Assert.Equal(new Size(184, 184), target.ArrangeFinalSize);
         }
 
+        [Fact]
+        public void ArrangeOverride_Receives_Requested_Size_When_Arranged_To_DesiredSize()
+        {
+            var target = new TestControl
+            {
+                MeasureResult = new Size(100, 100),
+                HorizontalAlignment = HorizontalAlignment.Center,
+                VerticalAlignment = VerticalAlignment.Center,
+                Margin = new Thickness(8),
+            };
+
+            target.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
+            target.Arrange(new Rect(target.DesiredSize));
+
+            Assert.Equal(new Size(100, 100), target.ArrangeFinalSize);
+        }
+
         [Fact]
         public void Arrange_With_IsMeasureValid_False_Calls_Measure()
         {