diff --git a/src/Perspex.Controls/Canvas.cs b/src/Perspex.Controls/Canvas.cs index 99b7cdd37d..950c7b3841 100644 --- a/src/Perspex.Controls/Canvas.cs +++ b/src/Perspex.Controls/Canvas.cs @@ -20,6 +20,18 @@ namespace Perspex.Controls public static readonly PerspexProperty TopProperty = PerspexProperty.RegisterAttached("Top"); + /// + /// Defines the property. + /// + public static readonly PerspexProperty RightProperty = + PerspexProperty.RegisterAttached("Right"); + + /// + /// Defines the property. + /// + public static readonly PerspexProperty BottomProperty = + PerspexProperty.RegisterAttached("Bottom"); + /// /// Initializes static members of the class. /// @@ -27,6 +39,8 @@ namespace Perspex.Controls { AffectsArrange(LeftProperty); AffectsArrange(TopProperty); + AffectsArrange(RightProperty); + AffectsArrange(BottomProperty); } /// @@ -69,6 +83,46 @@ namespace Perspex.Controls element.SetValue(TopProperty, value); } + /// + /// Gets the value of the Right attached property for a control. + /// + /// The control. + /// The control's right coordinate. + public static double GetRight(PerspexObject element) + { + return element.GetValue(RightProperty); + } + + /// + /// Sets the value of the Right attached property for a control. + /// + /// The control. + /// The right value. + public static void SetRight(PerspexObject element, double value) + { + element.SetValue(RightProperty, value); + } + + /// + /// Gets the value of the Bottom attached property for a control. + /// + /// The control. + /// The control's bottom coordinate. + public static double GetBottom(PerspexObject element) + { + return element.GetValue(BottomProperty); + } + + /// + /// Sets the value of the Bottom attached property for a control. + /// + /// The control. + /// The bottom value. + public static void SetBottom(PerspexObject element, double value) + { + element.SetValue(BottomProperty, value); + } + /// /// Gets the next control in the specified direction. /// @@ -111,16 +165,33 @@ namespace Perspex.Controls double y = 0.0; double elementLeft = GetLeft(child); - if (double.IsNaN(elementLeft) == false) + if (!double.IsNaN(elementLeft)) { x = elementLeft; } + else + { + // Arrange with right. + double elementRight = GetRight(child); + if (!double.IsNaN(elementRight)) + { + x = finalSize.Width - child.DesiredSize.Width - elementRight; + } + } double elementTop = GetTop(child); - if (double.IsNaN(elementTop) == false) + if (!double.IsNaN(elementTop) ) { y = elementTop; } + else + { + double elementBottom = GetBottom(child); + if (!double.IsNaN(elementBottom)) + { + y = finalSize.Height - child.DesiredSize.Height - elementBottom; + } + } child.Arrange(new Rect(new Point(x, y), child.DesiredSize)); }