diff --git a/src/Avalonia.Controls/Image.cs b/src/Avalonia.Controls/Image.cs
index 72379e7b53..c696fe7975 100644
--- a/src/Avalonia.Controls/Image.cs
+++ b/src/Avalonia.Controls/Image.cs
@@ -99,5 +99,22 @@ namespace Avalonia.Controls
return new Size();
}
}
+
+ ///
+ protected override Size ArrangeOverride(Size finalSize)
+ {
+ var source = Source;
+
+ if (source != null)
+ {
+ var sourceSize = new Size(source.PixelSize.Width, source.PixelSize.Height);
+ var result = Stretch.CalculateSize(finalSize, sourceSize);
+ return result;
+ }
+ else
+ {
+ return new Size();
+ }
+ }
}
}
diff --git a/tests/Avalonia.Controls.UnitTests/ImageTests.cs b/tests/Avalonia.Controls.UnitTests/ImageTests.cs
index e92fc572b4..71d0d1e328 100644
--- a/tests/Avalonia.Controls.UnitTests/ImageTests.cs
+++ b/tests/Avalonia.Controls.UnitTests/ImageTests.cs
@@ -61,5 +61,61 @@ namespace Avalonia.Controls.UnitTests
Assert.Equal(new Size(50, 50), target.DesiredSize);
}
+
+ [Fact]
+ public void Arrange_Should_Return_Correct_Size_For_No_Stretch()
+ {
+ var bitmap = Mock.Of(x => x.PixelSize == new PixelSize(50, 100));
+ var target = new Image();
+ target.Stretch = Stretch.None;
+ target.Source = bitmap;
+
+ target.Measure(new Size(50, 50));
+ target.Arrange(new Rect(0, 0, 100, 400));
+
+ Assert.Equal(new Size(50, 100), target.Bounds.Size);
+ }
+
+ [Fact]
+ public void Arrange_Should_Return_Correct_Size_For_Fill_Stretch()
+ {
+ var bitmap = Mock.Of(x => x.PixelSize == new PixelSize(50, 100));
+ var target = new Image();
+ target.Stretch = Stretch.Fill;
+ target.Source = bitmap;
+
+ target.Measure(new Size(50, 50));
+ target.Arrange(new Rect(0, 0, 25, 100));
+
+ Assert.Equal(new Size(25, 100), target.Bounds.Size);
+ }
+
+ [Fact]
+ public void Arrange_Should_Return_Correct_Size_For_Uniform_Stretch()
+ {
+ var bitmap = Mock.Of(x => x.PixelSize == new PixelSize(50, 100));
+ var target = new Image();
+ target.Stretch = Stretch.Uniform;
+ target.Source = bitmap;
+
+ target.Measure(new Size(50, 50));
+ target.Arrange(new Rect(0, 0, 25, 100));
+
+ Assert.Equal(new Size(25, 50), target.Bounds.Size);
+ }
+
+ [Fact]
+ public void Arrange_Should_Return_Correct_Size_For_UniformToFill_Stretch()
+ {
+ var bitmap = Mock.Of(x => x.PixelSize == new PixelSize(50, 100));
+ var target = new Image();
+ target.Stretch = Stretch.UniformToFill;
+ target.Source = bitmap;
+
+ target.Measure(new Size(50, 50));
+ target.Arrange(new Rect(0, 0, 25, 100));
+
+ Assert.Equal(new Size(25, 100), target.Bounds.Size);
+ }
}
}