diff --git a/src/Avalonia.Controls/Canvas.cs b/src/Avalonia.Controls/Canvas.cs
index fabf8978c7..adee7d4d90 100644
--- a/src/Avalonia.Controls/Canvas.cs
+++ b/src/Avalonia.Controls/Canvas.cs
@@ -1,4 +1,5 @@
using System;
+using System.Reactive.Concurrency;
using Avalonia.Input;
using Avalonia.Layout;
@@ -159,47 +160,57 @@ namespace Avalonia.Controls
}
///
- /// Arranges the control's children.
+ /// Arranges a single child.
///
- /// The size allocated to the control.
- /// The space taken.
- protected override Size ArrangeOverride(Size finalSize)
+ /// The child to arrange.
+ /// The size allocated to the canvas.
+ protected virtual void ArrangeChild(Control child, Size finalSize)
{
- foreach (Control child in Children)
- {
- double x = 0.0;
- double y = 0.0;
- double elementLeft = GetLeft(child);
+ double x = 0.0;
+ double y = 0.0;
+ double elementLeft = GetLeft(child);
- if (!double.IsNaN(elementLeft))
- {
- x = elementLeft;
- }
- else
+ if (!double.IsNaN(elementLeft))
+ {
+ x = elementLeft;
+ }
+ else
+ {
+ // Arrange with right.
+ double elementRight = GetRight(child);
+ if (!double.IsNaN(elementRight))
{
- // Arrange with right.
- double elementRight = GetRight(child);
- if (!double.IsNaN(elementRight))
- {
- x = finalSize.Width - child.DesiredSize.Width - elementRight;
- }
+ x = finalSize.Width - child.DesiredSize.Width - elementRight;
}
+ }
- double elementTop = GetTop(child);
- if (!double.IsNaN(elementTop) )
- {
- y = elementTop;
- }
- else
+ double elementTop = GetTop(child);
+ if (!double.IsNaN(elementTop))
+ {
+ y = elementTop;
+ }
+ else
+ {
+ double elementBottom = GetBottom(child);
+ if (!double.IsNaN(elementBottom))
{
- double elementBottom = GetBottom(child);
- if (!double.IsNaN(elementBottom))
- {
- y = finalSize.Height - child.DesiredSize.Height - elementBottom;
- }
+ y = finalSize.Height - child.DesiredSize.Height - elementBottom;
}
+ }
- child.Arrange(new Rect(new Point(x, y), child.DesiredSize));
+ child.Arrange(new Rect(new Point(x, y), child.DesiredSize));
+ }
+
+ ///
+ /// Arranges the control's children.
+ ///
+ /// The size allocated to the control.
+ /// The space taken.
+ protected override Size ArrangeOverride(Size finalSize)
+ {
+ foreach (Control child in Children)
+ {
+ ArrangeChild(child, finalSize);
}
return finalSize;
diff --git a/src/Avalonia.Controls/Primitives/AdornerLayer.cs b/src/Avalonia.Controls/Primitives/AdornerLayer.cs
index fb047d93df..5ad4e39baf 100644
--- a/src/Avalonia.Controls/Primitives/AdornerLayer.cs
+++ b/src/Avalonia.Controls/Primitives/AdornerLayer.cs
@@ -105,7 +105,7 @@ namespace Avalonia.Controls.Primitives
}
else
{
- child.Arrange(new Rect(finalSize));
+ ArrangeChild((Control) child, finalSize);
}
}
}