diff --git a/src/Avalonia.Controls/RelativePanel.AttachedProperties.cs b/src/Avalonia.Controls/RelativePanel.AttachedProperties.cs index 21baff87ab..a42eb6d428 100644 --- a/src/Avalonia.Controls/RelativePanel.AttachedProperties.cs +++ b/src/Avalonia.Controls/RelativePanel.AttachedProperties.cs @@ -1,16 +1,39 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Text; +using Avalonia.Layout; +using Avalonia.Markup.Xaml.Converters; namespace Avalonia.Controls { public partial class RelativePanel { - private static void OnAlignPropertiesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + private static void OnAlignPropertiesChanged(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e) { - var elm = d as FrameworkElement; - if (elm.Parent is FrameworkElement) - ((FrameworkElement)elm.Parent).InvalidateArrange(); + var elm = d as Layoutable; + if (elm.Parent is Layoutable) + ((Layoutable)elm.Parent).InvalidateArrange(); + } + + static RelativePanel() + { + AboveProperty.Changed.AddClassHandler(OnAlignPropertiesChanged); + AlignBottomWithPanelProperty.Changed.AddClassHandler(OnAlignPropertiesChanged); + AlignBottomWithProperty.Changed.AddClassHandler(OnAlignPropertiesChanged); + AlignHorizontalCenterWithPanelProperty.Changed.AddClassHandler(OnAlignPropertiesChanged); + AlignHorizontalCenterWithProperty.Changed.AddClassHandler(OnAlignPropertiesChanged); + AlignLeftWithPanelProperty.Changed.AddClassHandler(OnAlignPropertiesChanged); + AlignLeftWithProperty.Changed.AddClassHandler(OnAlignPropertiesChanged); + AlignRightWithPanelProperty.Changed.AddClassHandler(OnAlignPropertiesChanged); + AlignRightWithProperty.Changed.AddClassHandler(OnAlignPropertiesChanged); + AlignTopWithPanelProperty.Changed.AddClassHandler(OnAlignPropertiesChanged); + AlignTopWithProperty.Changed.AddClassHandler(OnAlignPropertiesChanged); + AlignVerticalCenterWithPanelProperty.Changed.AddClassHandler(OnAlignPropertiesChanged); + AlignVerticalCenterWithProperty.Changed.AddClassHandler(OnAlignPropertiesChanged); + BelowProperty.Changed.AddClassHandler(OnAlignPropertiesChanged); + LeftOfProperty.Changed.AddClassHandler(OnAlignPropertiesChanged); + LeftOfProperty.Changed.AddClassHandler(OnAlignPropertiesChanged); } /// @@ -22,7 +45,7 @@ namespace Avalonia.Controls /// (The element to position this element above.) /// [TypeConverter(typeof(NameReferenceConverter))] - public static object GetAbove(DependencyObject obj) + public static object GetAbove(AvaloniaObject obj) { return (object)obj.GetValue(AboveProperty); } @@ -32,7 +55,7 @@ namespace Avalonia.Controls /// /// The object to which the property value is written. /// The value to set. (The element to position this element above.) - public static void SetAbove(DependencyObject obj, object value) + public static void SetAbove(AvaloniaObject obj, object value) { obj.SetValue(AboveProperty, value); } @@ -40,8 +63,8 @@ namespace Avalonia.Controls /// /// Identifies the XAML attached property. /// - public static readonly DependencyProperty AboveProperty = - DependencyProperty.RegisterAttached("Above", typeof(object), typeof(RelativePanel), new PropertyMetadata(null, OnAlignPropertiesChanged)); + public static readonly AttachedProperty AboveProperty = + AvaloniaProperty.RegisterAttached("Above", typeof(RelativePanel)); /// @@ -53,7 +76,7 @@ namespace Avalonia.Controls /// object. (true to align this element's bottom edge with the panel's bottom edge; /// otherwise, false.) /// - public static bool GetAlignBottomWithPanel(DependencyObject obj) + public static bool GetAlignBottomWithPanel(AvaloniaObject obj) { return (bool)obj.GetValue(AlignBottomWithPanelProperty); } @@ -66,7 +89,7 @@ namespace Avalonia.Controls /// The value to set. (true to align this element's bottom edge with the panel's /// bottom edge; otherwise, false.) /// - public static void SetAlignBottomWithPanel(DependencyObject obj, bool value) + public static void SetAlignBottomWithPanel(AvaloniaObject obj, bool value) { obj.SetValue(AlignBottomWithPanelProperty, value); } @@ -74,8 +97,8 @@ namespace Avalonia.Controls /// /// Identifies the XAML attached property. /// - public static readonly DependencyProperty AlignBottomWithPanelProperty = - DependencyProperty.RegisterAttached("AlignBottomWithPanel", typeof(bool), typeof(RelativePanel), new PropertyMetadata(false, OnAlignPropertiesChanged)); + public static readonly AttachedProperty AlignBottomWithPanelProperty = + AvaloniaProperty.RegisterAttached("AlignBottomWithPanel", typeof(RelativePanel)); /// /// Gets the value of the RelativePanel.AlignBottomWith XAML attached property for the target element. @@ -86,7 +109,7 @@ namespace Avalonia.Controls /// (The element to align this element's bottom edge with.) /// [TypeConverter(typeof(NameReferenceConverter))] - public static object GetAlignBottomWith(DependencyObject obj) + public static object GetAlignBottomWith(AvaloniaObject obj) { return (object)obj.GetValue(AlignBottomWithProperty); } @@ -96,7 +119,7 @@ namespace Avalonia.Controls /// /// The object to which the property value is written. /// The value to set. (The element to align this element's bottom edge with.) - public static void SetAlignBottomWith(DependencyObject obj, object value) + public static void SetAlignBottomWith(AvaloniaObject obj, object value) { obj.SetValue(AlignBottomWithProperty, value); } @@ -104,8 +127,8 @@ namespace Avalonia.Controls /// /// Identifies the XAML attached property. /// - public static readonly DependencyProperty AlignBottomWithProperty = - DependencyProperty.RegisterAttached("AlignBottomWith", typeof(object), typeof(RelativePanel), new PropertyMetadata(null, OnAlignPropertiesChanged)); + public static readonly AttachedProperty AlignBottomWithProperty = + AvaloniaProperty.RegisterAttached("AlignBottomWith", typeof(RelativePanel)); /// /// Gets the value of the RelativePanel.AlignHorizontalCenterWithPanel XAML attached property for the target element. @@ -116,7 +139,7 @@ namespace Avalonia.Controls /// of the specified object. (true to horizontally center this element in the panel; /// otherwise, false.) /// - public static bool GetAlignHorizontalCenterWithPanel(DependencyObject obj) + public static bool GetAlignHorizontalCenterWithPanel(AvaloniaObject obj) { return (bool)obj.GetValue(AlignHorizontalCenterWithPanelProperty); } @@ -129,7 +152,7 @@ namespace Avalonia.Controls /// The value to set. (true to horizontally center this element in the panel; otherwise, /// false.) /// - public static void SetAlignHorizontalCenterWithPanel(DependencyObject obj, bool value) + public static void SetAlignHorizontalCenterWithPanel(AvaloniaObject obj, bool value) { obj.SetValue(AlignHorizontalCenterWithPanelProperty, value); } @@ -137,8 +160,8 @@ namespace Avalonia.Controls /// /// Identifies the XAML attached property. /// - public static readonly DependencyProperty AlignHorizontalCenterWithPanelProperty = - DependencyProperty.RegisterAttached("AlignHorizontalCenterWithPanel", typeof(bool), typeof(RelativePanel), new PropertyMetadata(false, OnAlignPropertiesChanged)); + public static readonly AttachedProperty AlignHorizontalCenterWithPanelProperty = + AvaloniaProperty.RegisterAttached("AlignHorizontalCenterWithPanel", typeof(RelativePanel), false); /// /// Gets the value of the RelativePanel.AlignHorizontalCenterWith XAML attached property for the target element. @@ -149,7 +172,7 @@ namespace Avalonia.Controls /// specified object. (The element to align this element's horizontal center with.) /// [TypeConverter(typeof(NameReferenceConverter))] - public static object GetAlignHorizontalCenterWith(DependencyObject obj) + public static object GetAlignHorizontalCenterWith(AvaloniaObject obj) { return (object)obj.GetValue(AlignHorizontalCenterWithProperty); } @@ -159,7 +182,7 @@ namespace Avalonia.Controls /// /// The object to which the property value is written. /// The value to set. (The element to align this element's horizontal center with.) - public static void SetAlignHorizontalCenterWith(DependencyObject obj, object value) + public static void SetAlignHorizontalCenterWith(AvaloniaObject obj, object value) { obj.SetValue(AlignHorizontalCenterWithProperty, value); } @@ -167,8 +190,8 @@ namespace Avalonia.Controls /// /// Identifies the XAML attached property. /// - public static readonly DependencyProperty AlignHorizontalCenterWithProperty = - DependencyProperty.RegisterAttached("AlignHorizontalCenterWith", typeof(object), typeof(RelativePanel), new PropertyMetadata(null, OnAlignPropertiesChanged)); + public static readonly AttachedProperty AlignHorizontalCenterWithProperty = + AvaloniaProperty.RegisterAttached("AlignHorizontalCenterWith", typeof(object), typeof(RelativePanel)); /// /// Gets the value of the RelativePanel.AlignLeftWithPanel XAML attached property for the target element. @@ -179,7 +202,7 @@ namespace Avalonia.Controls /// object. (true to align this element's left edge with the panel's left edge; otherwise, /// false.) /// - public static bool GetAlignLeftWithPanel(DependencyObject obj) + public static bool GetAlignLeftWithPanel(AvaloniaObject obj) { return (bool)obj.GetValue(AlignLeftWithPanelProperty); } @@ -192,7 +215,7 @@ namespace Avalonia.Controls /// The value to set. (true to align this element's left edge with the panel's left /// edge; otherwise, false.) /// - public static void SetAlignLeftWithPanel(DependencyObject obj, bool value) + public static void SetAlignLeftWithPanel(AvaloniaObject obj, bool value) { obj.SetValue(AlignLeftWithPanelProperty, value); } @@ -200,8 +223,8 @@ namespace Avalonia.Controls /// /// Identifies the XAML attached property. /// - public static readonly DependencyProperty AlignLeftWithPanelProperty = - DependencyProperty.RegisterAttached("AlignLeftWithPanel", typeof(bool), typeof(RelativePanel), new PropertyMetadata(false, OnAlignPropertiesChanged)); + public static readonly AttachedProperty AlignLeftWithPanelProperty = + AvaloniaProperty.RegisterAttached("AlignLeftWithPanel", typeof(RelativePanel), false); /// @@ -213,7 +236,7 @@ namespace Avalonia.Controls /// object. (The element to align this element's left edge with.) /// [TypeConverter(typeof(NameReferenceConverter))] - public static object GetAlignLeftWith(DependencyObject obj) + public static object GetAlignLeftWith(AvaloniaObject obj) { return (object)obj.GetValue(AlignLeftWithProperty); } @@ -223,7 +246,7 @@ namespace Avalonia.Controls /// /// The object to which the property value is written. /// The value to set. (The element to align this element's left edge with.) - public static void SetAlignLeftWith(DependencyObject obj, object value) + public static void SetAlignLeftWith(AvaloniaObject obj, object value) { obj.SetValue(AlignLeftWithProperty, value); } @@ -231,8 +254,8 @@ namespace Avalonia.Controls /// /// Identifies the XAML attached property. /// - public static readonly DependencyProperty AlignLeftWithProperty = - DependencyProperty.RegisterAttached("AlignLeftWith", typeof(object), typeof(RelativePanel), new PropertyMetadata(null, OnAlignPropertiesChanged)); + public static readonly AttachedProperty AlignLeftWithProperty = + AvaloniaProperty.RegisterAttached("AlignLeftWith"); /// @@ -244,7 +267,7 @@ namespace Avalonia.Controls /// object. (true to align this element's right edge with the panel's right edge; /// otherwise, false.) /// - public static bool GetAlignRightWithPanel(DependencyObject obj) + public static bool GetAlignRightWithPanel(AvaloniaObject obj) { return (bool)obj.GetValue(AlignRightWithPanelProperty); } @@ -257,7 +280,7 @@ namespace Avalonia.Controls /// The value to set. (true to align this element's right edge with the panel's right /// edge; otherwise, false.) /// - public static void SetAlignRightWithPanel(DependencyObject obj, bool value) + public static void SetAlignRightWithPanel(AvaloniaObject obj, bool value) { obj.SetValue(AlignRightWithPanelProperty, value); } @@ -265,8 +288,8 @@ namespace Avalonia.Controls /// /// Identifies the XAML attached property. /// - public static readonly DependencyProperty AlignRightWithPanelProperty = - DependencyProperty.RegisterAttached("AlignRightWithPanel", typeof(bool), typeof(RelativePanel), new PropertyMetadata(false, OnAlignPropertiesChanged)); + public static readonly AttachedProperty AlignRightWithPanelProperty = + AvaloniaProperty.RegisterAttached("AlignRightWithPanel", false); /// /// Gets the value of the RelativePanel.AlignRightWith XAML attached property for the target element. @@ -277,7 +300,7 @@ namespace Avalonia.Controls /// object. (The element to align this element's right edge with.) /// [TypeConverter(typeof(NameReferenceConverter))] - public static object GetAlignRightWith(DependencyObject obj) + public static object GetAlignRightWith(AvaloniaObject obj) { return (object)obj.GetValue(AlignRightWithProperty); } @@ -287,7 +310,7 @@ namespace Avalonia.Controls /// /// The object to which the property value is written. /// The value to set. (The element to align this element's right edge with.) - public static void SetAlignRightWith(DependencyObject obj, object value) + public static void SetAlignRightWith(AvaloniaObject obj, object value) { obj.SetValue(AlignRightWithProperty, value); } @@ -295,8 +318,8 @@ namespace Avalonia.Controls /// /// Identifies the XAML attached property. /// - public static readonly DependencyProperty AlignRightWithProperty = - DependencyProperty.RegisterAttached("AlignRightWith", typeof(object), typeof(RelativePanel), new PropertyMetadata(null, OnAlignPropertiesChanged)); + public static readonly AttachedProperty AlignRightWithProperty = + AvaloniaProperty.RegisterAttached("AlignRightWith"); /// /// Gets the value of the RelativePanel.AlignTopWithPanel XAML attached property for the target element. @@ -307,7 +330,7 @@ namespace Avalonia.Controls /// object. (true to align this element's top edge with the panel's top edge; otherwise, /// false.) /// - public static bool GetAlignTopWithPanel(DependencyObject obj) + public static bool GetAlignTopWithPanel(AvaloniaObject obj) { return (bool)obj.GetValue(AlignTopWithPanelProperty); } @@ -320,7 +343,7 @@ namespace Avalonia.Controls /// The value to set. (true to align this element's top edge with the panel's top /// edge; otherwise, false.) /// - public static void SetAlignTopWithPanel(DependencyObject obj, bool value) + public static void SetAlignTopWithPanel(AvaloniaObject obj, bool value) { obj.SetValue(AlignTopWithPanelProperty, value); } @@ -328,8 +351,8 @@ namespace Avalonia.Controls /// /// Identifies the XAML attached property. /// - public static readonly DependencyProperty AlignTopWithPanelProperty = - DependencyProperty.RegisterAttached("AlignTopWithPanel", typeof(bool), typeof(RelativePanel), new PropertyMetadata(false, OnAlignPropertiesChanged)); + public static readonly AttachedProperty AlignTopWithPanelProperty = + AvaloniaProperty.RegisterAttached("AlignTopWithPanel", false); /// /// Gets the value of the RelativePanel.AlignTopWith XAML attached property for the target element. @@ -337,7 +360,7 @@ namespace Avalonia.Controls /// The object from which the property value is read. /// The value to set. (The element to align this element's top edge with.) [TypeConverter(typeof(NameReferenceConverter))] - public static object GetAlignTopWith(DependencyObject obj) + public static object GetAlignTopWith(AvaloniaObject obj) { return (object)obj.GetValue(AlignTopWithProperty); } @@ -347,7 +370,7 @@ namespace Avalonia.Controls /// /// The object to which the property value is written. /// The value to set. (The element to align this element's top edge with.) - public static void SetAlignTopWith(DependencyObject obj, object value) + public static void SetAlignTopWith(AvaloniaObject obj, object value) { obj.SetValue(AlignTopWithProperty, value); } @@ -355,8 +378,8 @@ namespace Avalonia.Controls /// /// Identifies the XAML attached property. /// - public static readonly DependencyProperty AlignTopWithProperty = - DependencyProperty.RegisterAttached("AlignTopWith", typeof(object), typeof(RelativePanel), new PropertyMetadata(null, OnAlignPropertiesChanged)); + public static readonly AttachedProperty AlignTopWithProperty = + AvaloniaProperty.RegisterAttached("AlignTopWith"); /// /// Gets the value of the RelativePanel.AlignVerticalCenterWithPanel XAML attached property for the target element. @@ -367,7 +390,7 @@ namespace Avalonia.Controls /// the specified object. (true to vertically center this element in the panel; otherwise, /// false.) /// - public static bool GetAlignVerticalCenterWithPanel(DependencyObject obj) + public static bool GetAlignVerticalCenterWithPanel(AvaloniaObject obj) { return (bool)obj.GetValue(AlignVerticalCenterWithPanelProperty); } @@ -380,7 +403,7 @@ namespace Avalonia.Controls /// The value to set. (true to vertically center this element in the panel; otherwise, /// false.) /// - public static void SetAlignVerticalCenterWithPanel(DependencyObject obj, bool value) + public static void SetAlignVerticalCenterWithPanel(AvaloniaObject obj, bool value) { obj.SetValue(AlignVerticalCenterWithPanelProperty, value); } @@ -388,8 +411,8 @@ namespace Avalonia.Controls /// /// Identifies the XAML attached property. /// - public static readonly DependencyProperty AlignVerticalCenterWithPanelProperty = - DependencyProperty.RegisterAttached("AlignVerticalCenterWithPanel", typeof(bool), typeof(RelativePanel), new PropertyMetadata(false, OnAlignPropertiesChanged)); + public static readonly AttachedProperty AlignVerticalCenterWithPanelProperty = + AvaloniaProperty.RegisterAttached("AlignVerticalCenterWithPanel", false); /// /// Gets the value of the RelativePanel.AlignVerticalCenterWith XAML attached property for the target element. @@ -397,7 +420,7 @@ namespace Avalonia.Controls /// The object from which the property value is read. /// The value to set. (The element to align this element's vertical center with.) [TypeConverter(typeof(NameReferenceConverter))] - public static object GetAlignVerticalCenterWith(DependencyObject obj) + public static object GetAlignVerticalCenterWith(AvaloniaObject obj) { return (object)obj.GetValue(AlignVerticalCenterWithProperty); } @@ -407,7 +430,7 @@ namespace Avalonia.Controls /// /// The object to which the property value is written. /// The value to set. (The element to align this element's horizontal center with.) - public static void SetAlignVerticalCenterWith(DependencyObject obj, object value) + public static void SetAlignVerticalCenterWith(AvaloniaObject obj, object value) { obj.SetValue(AlignVerticalCenterWithProperty, value); } @@ -415,8 +438,8 @@ namespace Avalonia.Controls /// /// Identifies the XAML attached property. /// - public static readonly DependencyProperty AlignVerticalCenterWithProperty = - DependencyProperty.RegisterAttached("AlignVerticalCenterWith", typeof(object), typeof(RelativePanel), new PropertyMetadata(null, OnAlignPropertiesChanged)); + public static readonly AttachedProperty AlignVerticalCenterWithProperty = + AvaloniaProperty.RegisterAttached("AlignVerticalCenterWith"); /// /// Gets the value of the RelativePanel.Below XAML attached property for the target element. @@ -427,7 +450,7 @@ namespace Avalonia.Controls /// (The element to position this element below.) /// [TypeConverter(typeof(NameReferenceConverter))] - public static object GetBelow(DependencyObject obj) + public static object GetBelow(AvaloniaObject obj) { return (object)obj.GetValue(BelowProperty); } @@ -437,7 +460,7 @@ namespace Avalonia.Controls /// /// The object to which the property value is written. /// The value to set. (The element to position this element below.) - public static void SetBelow(DependencyObject obj, object value) + public static void SetBelow(AvaloniaObject obj, object value) { obj.SetValue(BelowProperty, value); } @@ -445,8 +468,8 @@ namespace Avalonia.Controls /// /// Identifies the XAML attached property. /// - public static readonly DependencyProperty BelowProperty = - DependencyProperty.RegisterAttached("Below", typeof(object), typeof(RelativePanel), new PropertyMetadata(null, OnAlignPropertiesChanged)); + public static readonly AttachedProperty BelowProperty = + AvaloniaProperty.RegisterAttached("Below"); /// /// Gets the value of the RelativePanel.LeftOf XAML attached property for the target element. @@ -457,7 +480,7 @@ namespace Avalonia.Controls /// (The element to position this element to the left of.) /// [TypeConverter(typeof(NameReferenceConverter))] - public static object GetLeftOf(DependencyObject obj) + public static object GetLeftOf(AvaloniaObject obj) { return (object)obj.GetValue(LeftOfProperty); } @@ -467,7 +490,7 @@ namespace Avalonia.Controls /// /// The object to which the property value is written. /// The value to set. (The element to position this element to the left of.) - public static void SetLeftOf(DependencyObject obj, object value) + public static void SetLeftOf(AvaloniaObject obj, object value) { obj.SetValue(LeftOfProperty, value); } @@ -475,8 +498,8 @@ namespace Avalonia.Controls /// /// Identifies the XAML attached property. /// - public static readonly DependencyProperty LeftOfProperty = - DependencyProperty.RegisterAttached("LeftOf", typeof(object), typeof(RelativePanel), new PropertyMetadata(null, OnAlignPropertiesChanged)); + public static readonly AttachedProperty LeftOfProperty = + AvaloniaProperty.RegisterAttached("LeftOf"); /// /// Gets the value of the RelativePanel.RightOf XAML attached property for the target element. @@ -487,7 +510,7 @@ namespace Avalonia.Controls /// (The element to position this element to the right of.) /// [TypeConverter(typeof(NameReferenceConverter))] - public static object GetRightOf(DependencyObject obj) + public static object GetRightOf(AvaloniaObject obj) { return (object)obj.GetValue(RightOfProperty); } @@ -497,7 +520,7 @@ namespace Avalonia.Controls /// /// The object to which the property value is written. /// The value to set. (The element to position this element to the right of.) - public static void SetRightOf(DependencyObject obj, object value) + public static void SetRightOf(AvaloniaObject obj, object value) { obj.SetValue(RightOfProperty, value); } @@ -505,7 +528,7 @@ namespace Avalonia.Controls /// /// Identifies the XAML attached property. /// - public static readonly DependencyProperty RightOfProperty = - DependencyProperty.RegisterAttached("RightOf", typeof(object), typeof(RelativePanel), new PropertyMetadata(null, OnAlignPropertiesChanged)); + public static readonly AttachedProperty RightOfProperty = + AvaloniaProperty.RegisterAttached("RightOf"); } } diff --git a/src/Avalonia.Controls/RelativePanel.cs b/src/Avalonia.Controls/RelativePanel.cs index aecd4b7c98..f1989de570 100644 --- a/src/Avalonia.Controls/RelativePanel.cs +++ b/src/Avalonia.Controls/RelativePanel.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; -using System.Text; +using System.Linq; +using Avalonia.Layout; namespace Avalonia.Controls { @@ -37,8 +38,8 @@ namespace Avalonia.Controls public partial class RelativePanel : Panel { // Dependency property for storing intermediate arrange state on the children - private static readonly DependencyProperty ArrangeStateProperty = - DependencyProperty.Register("ArrangeState", typeof(double[]), typeof(RelativePanel), new PropertyMetadata(null)); + private static readonly StyledProperty ArrangeStateProperty = + AvaloniaProperty.Register("ArrangeState"); /// /// When overridden in a derived class, measures the size in layout required for @@ -55,7 +56,7 @@ namespace Avalonia.Controls /// protected override Size MeasureOverride(Size availableSize) { - foreach (var child in Children.OfType()) + foreach (var child in Children.OfType()) { child.Measure(availableSize); } @@ -83,13 +84,13 @@ namespace Avalonia.Controls return base.ArrangeOverride(finalSize); } - private IEnumerable> CalculateLocations(Size finalSize) + private IEnumerable> CalculateLocations(Size finalSize) { //List of margins for each element between the element and panel (left, top, right, bottom) List arranges = new List(Children.Count); //First pass aligns all sides that aren't constrained by other elements int arrangedCount = 0; - foreach (var child in Children.OfType()) + foreach (var child in Children.OfType()) { //NaN means the arrange value is not constrained yet for that side double[] rect = new[] { double.NaN, double.NaN, double.NaN, double.NaN }; @@ -168,7 +169,7 @@ namespace Avalonia.Controls { bool valueChanged = false; i = 0; - foreach (var child in Children.OfType()) + foreach (var child in Children.OfType()) { double[] rect = arranges[i++]; @@ -386,7 +387,7 @@ namespace Avalonia.Controls i = 0; //Arrange iterations complete - Apply the results to the child elements - foreach (var child in Children.OfType()) + foreach (var child in Children.OfType()) { double[] rect = arranges[i++]; //Measure child again with the new calculated available size @@ -401,24 +402,24 @@ namespace Avalonia.Controls // tb.ArrangeOverride(new Rect(rect[0], rect[1], Math.Max(0, finalSize.Width - rect[2] - rect[0]), Math.Max(0, finalSize.Height - rect[3] - rect[1]))); //} //else - yield return new Tuple(child, new Rect(rect[0], rect[1], Math.Max(0, finalSize.Width - rect[2] - rect[0]), Math.Max(0, finalSize.Height - rect[3] - rect[1]))); + yield return new Tuple(child, new Rect(rect[0], rect[1], Math.Max(0, finalSize.Width - rect[2] - rect[0]), Math.Max(0, finalSize.Height - rect[3] - rect[1]))); } } //Gets the element that's referred to in the alignment attached properties - private UIElement GetDependencyElement(DependencyProperty property, DependencyObject child) + private Layoutable GetDependencyElement(AvaloniaProperty property, AvaloniaObject child) { var dependency = child.GetValue(property); if (dependency == null) return null; - if (dependency is UIElement) + if (dependency is Layoutable) { - if (Children.Contains((UIElement)dependency)) - return (UIElement)dependency; + if (Children.Contains((ILayoutable)dependency)) + return (Layoutable)dependency; throw new ArgumentException(string.Format("RelativePanel error: Element does not exist in the current context", property.Name)); } - throw new ArgumentException("RelativePanel error: Value must be of type UIElement"); + throw new ArgumentException("RelativePanel error: Value must be of type ILayoutable"); } } } diff --git a/src/Markup/Avalonia.Markup.Xaml/Avalonia.Markup.Xaml.csproj b/src/Markup/Avalonia.Markup.Xaml/Avalonia.Markup.Xaml.csproj index 06c5375520..724d910b62 100644 --- a/src/Markup/Avalonia.Markup.Xaml/Avalonia.Markup.Xaml.csproj +++ b/src/Markup/Avalonia.Markup.Xaml/Avalonia.Markup.Xaml.csproj @@ -12,6 +12,7 @@ + diff --git a/src/Markup/Avalonia.Markup.Xaml/Converters/NameReferenceConverter.cs b/src/Markup/Avalonia.Markup.Xaml/Converters/NameReferenceConverter.cs new file mode 100644 index 0000000000..885648ffde --- /dev/null +++ b/src/Markup/Avalonia.Markup.Xaml/Converters/NameReferenceConverter.cs @@ -0,0 +1,82 @@ +using Avalonia.Controls; +using Avalonia.Media.Imaging; +using Avalonia.Platform; +using System; +using System.ComponentModel; +using System.Globalization; + +namespace Avalonia.Markup.Xaml.Converters +{ + public class NameReferenceConverter : TypeConverter + { + public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) + { + if (sourceType == typeof(string)) + { + return true; + } + + return base.CanConvertFrom(context, sourceType); + } + + public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) + { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + //var nameResolver = (IXamlNameResolver)context.GetService(typeof(IXamlNameResolver)); + //if (nameResolver == null) + //{ + // throw new InvalidOperationException(SR.Get(SRID.MissingNameResolver)); + //} + + //string name = value as string; + //if (String.IsNullOrEmpty(name)) + //{ + // throw new InvalidOperationException(SR.Get(SRID.MustHaveName)); + //} + //object obj = nameResolver.Resolve(name); + //if (obj == null) + //{ + // string[] names = new string[] { name }; + // obj = nameResolver.GetFixupToken(names, true); + //} + return null; //obj; + } + + public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) + { + //if (context == null || (context.GetService(typeof(IXamlNameProvider)) as IXamlNameProvider) == null) + //{ + // return false; + //} + + //if (destinationType == typeof(string)) + //{ + // return true; + //} + + return base.CanConvertTo(context, destinationType); + + } + + public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) + { + //if (context == null) + //{ + // throw new ArgumentNullException(nameof(context)); + //} + + //var nameProvider = (IXamlNameProvider)context.GetService(typeof(IXamlNameProvider)); + //if (nameProvider == null) + //{ + // throw new InvalidOperationException(SR.Get(SRID.MissingNameProvider)); + //} + + //return nameProvider.GetName(value); + return null; + } + } +}