From 193025708f21a062c322d3db7993844aafca79de Mon Sep 17 00:00:00 2001 From: Elie Bariche <33458222+ebariche@users.noreply.github.com> Date: Thu, 22 Jul 2021 02:06:53 -0400 Subject: [PATCH] feat: Align Panel DPs --- .../UITests/Views/Controls/StarStackPanel.cs | 2 - .../LayoutPanel/LayoutPanel.Properties.cs | 64 ++++++++++- .../Xaml/Controls/LayoutPanel/LayoutPanel.cs | 50 +++++---- src/Uno.UI/Mock/Panel.net.cs | 2 +- src/Uno.UI/Mock/Panel.netstdref.cs | 2 +- .../UI/Xaml/Controls/Grid/Grid.Properties.cs | 85 +++++++++++++++ .../UI/Xaml/Controls/Panel/Panel.Android.cs | 12 +- src/Uno.UI/UI/Xaml/Controls/Panel/Panel.cs | 103 +----------------- .../UI/Xaml/Controls/Panel/Panel.iOS.cs | 8 +- .../UI/Xaml/Controls/Panel/Panel.macOS.cs | 8 +- .../UI/Xaml/Controls/Panel/Panel.skia.cs | 8 +- .../UI/Xaml/Controls/Panel/Panel.wasm.cs | 4 +- .../Xaml/Controls/Pivot/PivotHeaderPanel.cs | 13 +-- .../RelativePanel/RelativePanel.Properties.cs | 85 +++++++++++++++ .../UI/Xaml/Controls/StackPanel/StackPanel.cs | 101 ++++++++++++++++- .../UI/Xaml/FrameworkElementExtensions.cs | 60 ++++++---- 16 files changed, 429 insertions(+), 178 deletions(-) diff --git a/src/SamplesApp/SamplesApp.UnitTests.Shared/Controls/UITests/Views/Controls/StarStackPanel.cs b/src/SamplesApp/SamplesApp.UnitTests.Shared/Controls/UITests/Views/Controls/StarStackPanel.cs index 930fe9a087b0..cdb0d3f615d0 100644 --- a/src/SamplesApp/SamplesApp.UnitTests.Shared/Controls/UITests/Views/Controls/StarStackPanel.cs +++ b/src/SamplesApp/SamplesApp.UnitTests.Shared/Controls/UITests/Views/Controls/StarStackPanel.cs @@ -634,7 +634,6 @@ private static void HandleSizePropertyChanged(DependencyObject d, DependencyProp } #endregion -#if !__ANDROID__ && !__IOS__ && !UNO_REFERENCE_API //In Uno, Padding is (incorrectly) defined on Panel #region Padding DependencyProperty public Thickness Padding @@ -648,7 +647,6 @@ public Thickness Padding DependencyProperty.Register("Padding", typeof(Thickness), typeof(StarStackPanel), new PropertyMetadata(default(Thickness), InvalidateLayoutOnChanged)); #endregion -#endif #region struct Record private struct Record diff --git a/src/Uno.UI/Microsoft/UI/Xaml/Controls/LayoutPanel/LayoutPanel.Properties.cs b/src/Uno.UI/Microsoft/UI/Xaml/Controls/LayoutPanel/LayoutPanel.Properties.cs index 27dd7e95c68e..869d4300ba2c 100644 --- a/src/Uno.UI/Microsoft/UI/Xaml/Controls/LayoutPanel/LayoutPanel.Properties.cs +++ b/src/Uno.UI/Microsoft/UI/Xaml/Controls/LayoutPanel/LayoutPanel.Properties.cs @@ -1,9 +1,71 @@ -using Windows.UI.Xaml; +using Uno.UI.Xaml; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Media; namespace Microsoft.UI.Xaml.Controls { partial class LayoutPanel { + #region BorderBrush DependencyProperty + + public Brush BorderBrush + { + get => GetBorderBrushValue(); + set => SetBorderBrushValue(value); + } + + private static Brush GetBorderBrushDefaultValue() => SolidColorBrushHelper.Transparent; + + [GeneratedDependencyProperty(ChangedCallback = false, Options = FrameworkPropertyMetadataOptions.ValueInheritsDataContext)] + public static DependencyProperty BorderBrushProperty { get; } = CreateBorderBrushProperty(); + + #endregion + + #region BorderThickness DependencyProperty + + public Thickness BorderThickness + { + get => GetBorderThicknessValue(); + set => SetBorderThicknessValue(value); + } + + private static Thickness GetBorderThicknessDefaultValue() => Thickness.Empty; + + [GeneratedDependencyProperty(ChangedCallback = false)] + public static DependencyProperty BorderThicknessProperty { get; } = CreateBorderThicknessProperty(); + + #endregion + + #region Padding DependencyProperty + + public Thickness Padding + { + get => GetPaddingValue(); + set => SetPaddingValue(value); + } + + private static Thickness GetPaddingDefaultValue() => Thickness.Empty; + + [GeneratedDependencyProperty(ChangedCallback = false)] + public static DependencyProperty PaddingProperty { get; } = CreatePaddingProperty(); + + #endregion + + #region CornerRadius DependencyProperty + + public CornerRadius CornerRadius + { + get => GetCornerRadiusValue(); + set => SetCornerRadiusValue(value); + } + + private static CornerRadius GetCornerRadiusDefaultValue() => CornerRadius.None; + + [GeneratedDependencyProperty(ChangedCallback = false)] + public static DependencyProperty CornerRadiusProperty { get; } = CreateCornerRadiusProperty(); + + #endregion + public static DependencyProperty LayoutProperty { get; } = DependencyProperty.Register( "Layout", typeof(Layout), typeof(LayoutPanel), new FrameworkPropertyMetadata(default(Layout))); diff --git a/src/Uno.UI/Microsoft/UI/Xaml/Controls/LayoutPanel/LayoutPanel.cs b/src/Uno.UI/Microsoft/UI/Xaml/Controls/LayoutPanel/LayoutPanel.cs index 276cf5f9bcb5..717d36e4ab45 100644 --- a/src/Uno.UI/Microsoft/UI/Xaml/Controls/LayoutPanel/LayoutPanel.cs +++ b/src/Uno.UI/Microsoft/UI/Xaml/Controls/LayoutPanel/LayoutPanel.cs @@ -6,6 +6,7 @@ using Windows.Foundation; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls.Primitives; +using Windows.UI.Xaml.Media; namespace Microsoft.UI.Xaml.Controls { @@ -27,31 +28,34 @@ void OnPropertyChanged(DependencyPropertyChangedEventArgs args) { OnLayoutChanged(args.OldValue as Layout, args.NewValue as Layout); } -#if USE_INTERNAL_SDK - else if (dependencyProperty == s_borderBrushProperty) - { - if (var panelProtected = try_as()) - { - panelProtected.BorderBrushProtected(Brush>(args.NewValue())); - } - } - else if (dependencyProperty == s_borderThicknessProperty) - { - if (var panelProtected = try_as()) - { - panelProtected.BorderThicknessProtected((Thickness)(args.NewValue())); - } - } - else if (dependencyProperty == s_cornerRadiusProperty) - { - if (var panelProtected = try_as()) - { - panelProtected.CornerRadiusProtected((CornerRadius)(args.NewValue())); - } - } -#endif + else if (dependencyProperty == BorderBrushProperty) + { + var newValue = (Brush)args.NewValue; + + BorderBrushInternal = newValue; + OnBorderBrushChanged((Brush)args.OldValue, newValue); + } + else if (dependencyProperty == BorderThicknessProperty) + { + var newValue = (Thickness)args.NewValue; + + BorderThicknessInternal = newValue; + OnBorderThicknessChanged((Thickness)args.OldValue, newValue); + } + else if (dependencyProperty == CornerRadiusProperty) + { + var newValue = (CornerRadius)args.NewValue; + + CornerRadiusInternal = newValue; + OnCornerRadiusChanged((CornerRadius)args.OldValue, newValue); + } else if (dependencyProperty == PaddingProperty) { + var newValue = (Thickness)args.NewValue; + + PaddingInternal = newValue; + OnPaddingChanged((Thickness)args.OldValue, newValue); + InvalidateMeasure(); } } diff --git a/src/Uno.UI/Mock/Panel.net.cs b/src/Uno.UI/Mock/Panel.net.cs index 804cde960858..72cddb646a26 100644 --- a/src/Uno.UI/Mock/Panel.net.cs +++ b/src/Uno.UI/Mock/Panel.net.cs @@ -32,6 +32,6 @@ public override IEnumerable GetChildren() => Children.OfType().ToArray(); bool ICustomClippingElement.AllowClippingToLayoutSlot => false; - bool ICustomClippingElement.ForceClippingToLayoutSlot => CornerRadius != CornerRadius.None; + bool ICustomClippingElement.ForceClippingToLayoutSlot => CornerRadiusInternal != CornerRadius.None; } } diff --git a/src/Uno.UI/Mock/Panel.netstdref.cs b/src/Uno.UI/Mock/Panel.netstdref.cs index 9e20056b726e..e8152384773f 100644 --- a/src/Uno.UI/Mock/Panel.netstdref.cs +++ b/src/Uno.UI/Mock/Panel.netstdref.cs @@ -29,6 +29,6 @@ protected virtual void OnChildrenChanged() } bool ICustomClippingElement.AllowClippingToLayoutSlot => false; - bool ICustomClippingElement.ForceClippingToLayoutSlot => CornerRadius != CornerRadius.None; + bool ICustomClippingElement.ForceClippingToLayoutSlot => CornerRadiusInternal != CornerRadius.None; } } diff --git a/src/Uno.UI/UI/Xaml/Controls/Grid/Grid.Properties.cs b/src/Uno.UI/UI/Xaml/Controls/Grid/Grid.Properties.cs index 7fe28024ceb7..1a877028ed62 100644 --- a/src/Uno.UI/UI/Xaml/Controls/Grid/Grid.Properties.cs +++ b/src/Uno.UI/UI/Xaml/Controls/Grid/Grid.Properties.cs @@ -6,6 +6,7 @@ using Uno.UI; using Uno.UI.Extensions; using Uno.UI.Xaml; +using Windows.UI.Xaml.Media; #if XAMARIN_ANDROID using View = Android.Views.View; @@ -45,6 +46,90 @@ private void OnBackgroundSizingChanged(DependencyPropertyChangedEventArgs e) } #endregion + #region BorderBrush DependencyProperty + + public Brush BorderBrush + { + get => GetBorderBrushValue(); + set => SetBorderBrushValue(value); + } + + private static Brush GetBorderBrushDefaultValue() => SolidColorBrushHelper.Transparent; + + [GeneratedDependencyProperty(ChangedCallbackName = nameof(OnBorderBrushPropertyChanged), Options = FrameworkPropertyMetadataOptions.ValueInheritsDataContext)] + public static DependencyProperty BorderBrushProperty { get; } = CreateBorderBrushProperty(); + + private void OnBorderBrushPropertyChanged(Brush oldValue, Brush newValue) + { + BorderBrushInternal = newValue; + OnBorderBrushChanged(oldValue, newValue); + } + + #endregion + + #region BorderThickness DependencyProperty + + public Thickness BorderThickness + { + get => GetBorderThicknessValue(); + set => SetBorderThicknessValue(value); + } + + private static Thickness GetBorderThicknessDefaultValue() => Thickness.Empty; + + [GeneratedDependencyProperty(ChangedCallbackName = nameof(OnBorderThicknessPropertyChanged))] + public static DependencyProperty BorderThicknessProperty { get; } = CreateBorderThicknessProperty(); + + private void OnBorderThicknessPropertyChanged(Thickness oldValue, Thickness newValue) + { + BorderThicknessInternal = newValue; + OnBorderThicknessChanged(oldValue, newValue); + } + + #endregion + + #region Padding DependencyProperty + + public Thickness Padding + { + get => GetPaddingValue(); + set => SetPaddingValue(value); + } + + private static Thickness GetPaddingDefaultValue() => Thickness.Empty; + + [GeneratedDependencyProperty(ChangedCallbackName = nameof(OnPaddingPropertyChanged))] + public static DependencyProperty PaddingProperty { get; } = CreatePaddingProperty(); + + private void OnPaddingPropertyChanged(Thickness oldValue, Thickness newValue) + { + PaddingInternal = newValue; + OnPaddingChanged(oldValue, newValue); + } + + #endregion + + #region CornerRadius DependencyProperty + + public CornerRadius CornerRadius + { + get => GetCornerRadiusValue(); + set => SetCornerRadiusValue(value); + } + + private static CornerRadius GetCornerRadiusDefaultValue() => CornerRadius.None; + + [GeneratedDependencyProperty(ChangedCallbackName = nameof(OnCornerRadiusPropertyChanged))] + public static DependencyProperty CornerRadiusProperty { get; } = CreateCornerRadiusProperty(); + + private void OnCornerRadiusPropertyChanged(CornerRadius oldValue, CornerRadius newValue) + { + CornerRadiusInternal = newValue; + OnCornerRadiusChanged(oldValue, newValue); + } + + #endregion + #region Row Property [GeneratedDependencyProperty(DefaultValue = 0, AttachedBackingFieldOwner = typeof(UIElement), Attached = true, ChangedCallbackName = nameof(OnGenericPropertyChanged))] public static DependencyProperty RowProperty { get ; } = CreateRowProperty(); diff --git a/src/Uno.UI/UI/Xaml/Controls/Panel/Panel.Android.cs b/src/Uno.UI/UI/Xaml/Controls/Panel/Panel.Android.cs index 349f3dca9f4d..185812de892f 100644 --- a/src/Uno.UI/UI/Xaml/Controls/Panel/Panel.Android.cs +++ b/src/Uno.UI/UI/Xaml/Controls/Panel/Panel.Android.cs @@ -57,10 +57,10 @@ private void UpdateBorder(bool willUpdateMeasures) this, Background, InternalBackgroundSizing, - BorderThickness, - BorderBrush, - CornerRadius, - Padding, + BorderThicknessInternal, + BorderBrushInternal, + CornerRadiusInternal, + PaddingInternal, willUpdateMeasures ); } @@ -75,7 +75,7 @@ protected override void OnLayoutCore(bool changed, int left, int top, int right, protected override void OnDraw(Android.Graphics.Canvas canvas) { - AdjustCornerRadius(canvas, CornerRadius); + AdjustCornerRadius(canvas, CornerRadiusInternal); } protected virtual void OnChildrenChanged() @@ -147,6 +147,6 @@ public IEnumerator GetEnumerator() } bool ICustomClippingElement.AllowClippingToLayoutSlot => true; - bool ICustomClippingElement.ForceClippingToLayoutSlot => CornerRadius != CornerRadius.None; + bool ICustomClippingElement.ForceClippingToLayoutSlot => CornerRadiusInternal != CornerRadius.None; } } diff --git a/src/Uno.UI/UI/Xaml/Controls/Panel/Panel.cs b/src/Uno.UI/UI/Xaml/Controls/Panel/Panel.cs index 7cc75263e0cb..cf3d1b271f31 100644 --- a/src/Uno.UI/UI/Xaml/Controls/Panel/Panel.cs +++ b/src/Uno.UI/UI/Xaml/Controls/Panel/Panel.cs @@ -108,106 +108,13 @@ private static void OnChildrenTransitionsChanged(object dependencyObject, Depend #endregion - #region Padding DependencyProperty + internal Thickness PaddingInternal { get; set; } - internal Size BorderAndPaddingSize - { - get - { - var border = BorderThickness; - var padding = Padding; - var width = border.Left + border.Right + padding.Left + padding.Right; - var height = border.Top + border.Bottom + padding.Top + padding.Bottom; - return new Size(width, height); - } - } - - public Thickness Padding - { - get { return (Thickness)this.GetValue(PaddingProperty); } - set { this.SetValue(PaddingProperty, value); } - } - - public static DependencyProperty PaddingProperty { get ; } = - DependencyProperty.Register( - "Padding", - typeof(Thickness), - typeof(Panel), - new FrameworkPropertyMetadata( - Thickness.Empty, - FrameworkPropertyMetadataOptions.None, - (s, e) => ((Panel)s)?.OnPaddingChanged((Thickness)e.OldValue, (Thickness)e.NewValue) - ) - ); - -#endregion + internal Thickness BorderThicknessInternal { get; set; } - #region BorderThickness DependencyProperty + internal Brush BorderBrushInternal { get; set; } - public Thickness BorderThickness - { - get { return (Thickness)this.GetValue(BorderThicknessProperty); } - set { this.SetValue(BorderThicknessProperty, value); } - } - - public static DependencyProperty BorderThicknessProperty { get ; } = - DependencyProperty.Register( - "BorderThickness", - typeof(Thickness), - typeof(Panel), - new FrameworkPropertyMetadata( - Thickness.Empty, - FrameworkPropertyMetadataOptions.None, - (s, e) => ((Panel)s)?.OnBorderThicknessChanged((Thickness)e.OldValue, (Thickness)e.NewValue) - ) - ); - - #endregion - - #region BorderBrush Dependency Property - -#if XAMARIN_ANDROID - private Brush _borderBrushStrongReference; -#endif - - public Brush BorderBrush - { - get { return (Brush)this.GetValue(BorderBrushProperty); } - set - { - this.SetValue(BorderBrushProperty, value); - -#if XAMARIN_ANDROID - _borderBrushStrongReference = value; -#endif - } - } - - public static DependencyProperty BorderBrushProperty { get ; } = - DependencyProperty.Register( - "BorderBrush", - typeof(Brush), - typeof(Panel), - new FrameworkPropertyMetadata( - SolidColorBrushHelper.Transparent, - FrameworkPropertyMetadataOptions.ValueInheritsDataContext, - propertyChangedCallback: (s, e) => ((Panel)s).OnBorderBrushChanged((Brush)e.OldValue, (Brush)e.NewValue) - ) - ); - #endregion - - #region CornerRadius DependencyProperty - private static CornerRadius GetCornerRadiusDefaultValue() => CornerRadius.None; - - [GeneratedDependencyProperty(ChangedCallback = true)] - public static DependencyProperty CornerRadiusProperty { get; } = CreateCornerRadiusProperty(); - - public CornerRadius CornerRadius - { - get => GetCornerRadiusValue(); - set => SetCornerRadiusValue(value); - } - #endregion + internal CornerRadius CornerRadiusInternal { get; set; } #region IsItemsHost DependencyProperty public static DependencyProperty IsItemsHostProperty { get ; } = DependencyProperty.Register( @@ -263,7 +170,7 @@ protected virtual void OnBorderBrushChanged(Brush oldValue, Brush newValue) } partial void OnBorderBrushChangedPartial(Brush oldValue, Brush newValue); - private protected override Thickness GetBorderThickness() => BorderThickness; + private protected override Thickness GetBorderThickness() => BorderThicknessInternal; internal override bool CanHaveChildren() => true; diff --git a/src/Uno.UI/UI/Xaml/Controls/Panel/Panel.iOS.cs b/src/Uno.UI/UI/Xaml/Controls/Panel/Panel.iOS.cs index cd30df7e0746..33dc4ef563bc 100644 --- a/src/Uno.UI/UI/Xaml/Controls/Panel/Panel.iOS.cs +++ b/src/Uno.UI/UI/Xaml/Controls/Panel/Panel.iOS.cs @@ -97,9 +97,9 @@ private void UpdateBackground(UIImage backgroundImage = null) this, Background, InternalBackgroundSizing, - BorderThickness, - BorderBrush, - CornerRadius, + BorderThicknessInternal, + BorderBrushInternal, + CornerRadiusInternal, backgroundImage ); } @@ -159,7 +159,7 @@ public override UIView HitTest(CGPoint point, UIEvent uievent) return HitTestOutsideFrame ? this.HitTestOutsideFrame(point, uievent) : base.HitTest(point, uievent); } - bool ICustomClippingElement.AllowClippingToLayoutSlot => CornerRadius == CornerRadius.None; + bool ICustomClippingElement.AllowClippingToLayoutSlot => CornerRadiusInternal == CornerRadius.None; bool ICustomClippingElement.ForceClippingToLayoutSlot => false; } } diff --git a/src/Uno.UI/UI/Xaml/Controls/Panel/Panel.macOS.cs b/src/Uno.UI/UI/Xaml/Controls/Panel/Panel.macOS.cs index 50e33543ca37..34e343feaca5 100644 --- a/src/Uno.UI/UI/Xaml/Controls/Panel/Panel.macOS.cs +++ b/src/Uno.UI/UI/Xaml/Controls/Panel/Panel.macOS.cs @@ -105,9 +105,9 @@ private void UpdateBackground(NSImage backgroundImage = null) this, Background, InternalBackgroundSizing, - BorderThickness, - BorderBrush, - CornerRadius, + BorderThicknessInternal, + BorderBrushInternal, + CornerRadiusInternal, backgroundImage ); } @@ -167,7 +167,7 @@ public override NSView HitTest(CGPoint point) return HitTestOutsideFrame ? this.HitTestOutsideFrame(point) : base.HitTest(point); } - bool ICustomClippingElement.AllowClippingToLayoutSlot => CornerRadius == CornerRadius.None; + bool ICustomClippingElement.AllowClippingToLayoutSlot => CornerRadiusInternal == CornerRadius.None; bool ICustomClippingElement.ForceClippingToLayoutSlot => false; } } diff --git a/src/Uno.UI/UI/Xaml/Controls/Panel/Panel.skia.cs b/src/Uno.UI/UI/Xaml/Controls/Panel/Panel.skia.cs index 38a9e3d37d10..cd96284b1807 100644 --- a/src/Uno.UI/UI/Xaml/Controls/Panel/Panel.skia.cs +++ b/src/Uno.UI/UI/Xaml/Controls/Panel/Panel.skia.cs @@ -44,9 +44,9 @@ partial void UpdateBorder() this, Background, InternalBackgroundSizing, - BorderThickness, - BorderBrush, - CornerRadius, + BorderThicknessInternal, + BorderBrushInternal, + CornerRadiusInternal, null ); } @@ -104,6 +104,6 @@ protected override void OnBackgroundChanged(DependencyPropertyChangedEventArgs e } bool ICustomClippingElement.AllowClippingToLayoutSlot => true; - bool ICustomClippingElement.ForceClippingToLayoutSlot => CornerRadius != CornerRadius.None; + bool ICustomClippingElement.ForceClippingToLayoutSlot => CornerRadiusInternal != CornerRadius.None; } } diff --git a/src/Uno.UI/UI/Xaml/Controls/Panel/Panel.wasm.cs b/src/Uno.UI/UI/Xaml/Controls/Panel/Panel.wasm.cs index 26d69851ef3f..886de459e11e 100644 --- a/src/Uno.UI/UI/Xaml/Controls/Panel/Panel.wasm.cs +++ b/src/Uno.UI/UI/Xaml/Controls/Panel/Panel.wasm.cs @@ -31,7 +31,7 @@ public Panel() partial void UpdateBorder() { - SetBorder(BorderThickness, BorderBrush); + SetBorder(BorderThicknessInternal, BorderBrushInternal); } protected virtual void OnChildrenChanged() @@ -91,6 +91,6 @@ protected override void OnBackgroundChanged(DependencyPropertyChangedEventArgs e } bool ICustomClippingElement.AllowClippingToLayoutSlot => true; - bool ICustomClippingElement.ForceClippingToLayoutSlot => CornerRadius != CornerRadius.None; + bool ICustomClippingElement.ForceClippingToLayoutSlot => CornerRadiusInternal != CornerRadius.None; } } diff --git a/src/Uno.UI/UI/Xaml/Controls/Pivot/PivotHeaderPanel.cs b/src/Uno.UI/UI/Xaml/Controls/Pivot/PivotHeaderPanel.cs index 5781a7f3865e..a5f7e062b7f8 100644 --- a/src/Uno.UI/UI/Xaml/Controls/Pivot/PivotHeaderPanel.cs +++ b/src/Uno.UI/UI/Xaml/Controls/Pivot/PivotHeaderPanel.cs @@ -9,9 +9,6 @@ public partial class PivotHeaderPanel : Canvas { protected override Size MeasureOverride(Size availableSize) { - var borderAndPaddingSize = BorderAndPaddingSize; - availableSize = availableSize.Subtract(borderAndPaddingSize); - var desiredSize = default(Size); var slotSize = availableSize; @@ -30,16 +27,12 @@ protected override Size MeasureOverride(Size availableSize) desiredSize.Height = Math.Max(desiredSize.Height, measuredSize.Height); } - return desiredSize.Add(borderAndPaddingSize); + return desiredSize; } protected override Size ArrangeOverride(Size arrangeSize) { - var borderAndPaddingSize = BorderAndPaddingSize; - arrangeSize = arrangeSize.Subtract(borderAndPaddingSize); - - var childRectangle = new Windows.Foundation.Rect(BorderThickness.Left + Padding.Left, BorderThickness.Top + Padding.Top, arrangeSize.Width, arrangeSize.Height); - + var childRectangle = new Windows.Foundation.Rect(0d, 0d, arrangeSize.Width, arrangeSize.Height); var previousChildSize = 0.0; @@ -60,7 +53,7 @@ protected override Size ArrangeOverride(Size arrangeSize) ArrangeElement(view, childRectangle); } - return arrangeSize.Add(borderAndPaddingSize); + return arrangeSize; } } } diff --git a/src/Uno.UI/UI/Xaml/Controls/RelativePanel/RelativePanel.Properties.cs b/src/Uno.UI/UI/Xaml/Controls/RelativePanel/RelativePanel.Properties.cs index 340f2441e994..0114e61ad102 100644 --- a/src/Uno.UI/UI/Xaml/Controls/RelativePanel/RelativePanel.Properties.cs +++ b/src/Uno.UI/UI/Xaml/Controls/RelativePanel/RelativePanel.Properties.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Text; using Uno.UI.Xaml; +using Windows.UI.Xaml.Media; namespace Windows.UI.Xaml.Controls { @@ -24,6 +25,90 @@ private void OnBackgroundSizingChanged(DependencyPropertyChangedEventArgs e) } #endregion + #region BorderBrush DependencyProperty + + public Brush BorderBrush + { + get => GetBorderBrushValue(); + set => SetBorderBrushValue(value); + } + + private static Brush GetBorderBrushDefaultValue() => SolidColorBrushHelper.Transparent; + + [GeneratedDependencyProperty(ChangedCallbackName = nameof(OnBorderBrushPropertyChanged), Options = FrameworkPropertyMetadataOptions.ValueInheritsDataContext)] + public static DependencyProperty BorderBrushProperty { get; } = CreateBorderBrushProperty(); + + private void OnBorderBrushPropertyChanged(Brush oldValue, Brush newValue) + { + BorderBrushInternal = newValue; + OnBorderBrushChanged(oldValue, newValue); + } + + #endregion + + #region BorderThickness DependencyProperty + + public Thickness BorderThickness + { + get => GetBorderThicknessValue(); + set => SetBorderThicknessValue(value); + } + + private static Thickness GetBorderThicknessDefaultValue() => Thickness.Empty; + + [GeneratedDependencyProperty(ChangedCallbackName = nameof(OnBorderThicknessPropertyChanged))] + public static DependencyProperty BorderThicknessProperty { get; } = CreateBorderThicknessProperty(); + + private void OnBorderThicknessPropertyChanged(Thickness oldValue, Thickness newValue) + { + BorderThicknessInternal = newValue; + OnBorderThicknessChanged(oldValue, newValue); + } + + #endregion + + #region Padding DependencyProperty + + public Thickness Padding + { + get => GetPaddingValue(); + set => SetPaddingValue(value); + } + + private static Thickness GetPaddingDefaultValue() => Thickness.Empty; + + [GeneratedDependencyProperty(ChangedCallbackName = nameof(OnPaddingPropertyChanged))] + public static DependencyProperty PaddingProperty { get; } = CreatePaddingProperty(); + + private void OnPaddingPropertyChanged(Thickness oldValue, Thickness newValue) + { + PaddingInternal = newValue; + OnPaddingChanged(oldValue, newValue); + } + + #endregion + + #region CornerRadius DependencyProperty + + public CornerRadius CornerRadius + { + get => GetCornerRadiusValue(); + set => SetCornerRadiusValue(value); + } + + private static CornerRadius GetCornerRadiusDefaultValue() => CornerRadius.None; + + [GeneratedDependencyProperty(ChangedCallbackName = nameof(OnCornerRadiusPropertyChanged))] + public static DependencyProperty CornerRadiusProperty { get; } = CreateCornerRadiusProperty(); + + private void OnCornerRadiusPropertyChanged(CornerRadius oldValue, CornerRadius newValue) + { + CornerRadiusInternal = newValue; + OnCornerRadiusChanged(oldValue, newValue); + } + + #endregion + #region Panel Alignment relationships public static bool GetAlignBottomWithPanel(DependencyObject view) diff --git a/src/Uno.UI/UI/Xaml/Controls/StackPanel/StackPanel.cs b/src/Uno.UI/UI/Xaml/Controls/StackPanel/StackPanel.cs index d443553bcae2..41cf132ad76c 100644 --- a/src/Uno.UI/UI/Xaml/Controls/StackPanel/StackPanel.cs +++ b/src/Uno.UI/UI/Xaml/Controls/StackPanel/StackPanel.cs @@ -1,12 +1,14 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Collections.Specialized; using System.Linq; -using Uno.Disposables; using System.Text; +using Uno.Disposables; using Uno.Extensions; -using System.Collections.Specialized; using Uno.UI.Xaml; +using Windows.Foundation; +using Windows.UI.Xaml.Media; #if XAMARIN_ANDROID using Android.Views; #elif XAMARIN_IOS @@ -38,6 +40,101 @@ private void OnBackgroundSizingChanged(DependencyPropertyChangedEventArgs e) } #endregion + #region BorderBrush DependencyProperty + + public Brush BorderBrush + { + get => GetBorderBrushValue(); + set => SetBorderBrushValue(value); + } + + private static Brush GetBorderBrushDefaultValue() => SolidColorBrushHelper.Transparent; + + [GeneratedDependencyProperty(ChangedCallbackName = nameof(OnBorderBrushPropertyChanged), Options = FrameworkPropertyMetadataOptions.ValueInheritsDataContext)] + public static DependencyProperty BorderBrushProperty { get; } = CreateBorderBrushProperty(); + + private void OnBorderBrushPropertyChanged(Brush oldValue, Brush newValue) + { + BorderBrushInternal = newValue; + OnBorderBrushChanged(oldValue, newValue); + } + + #endregion + + #region BorderThickness DependencyProperty + + public Thickness BorderThickness + { + get => GetBorderThicknessValue(); + set => SetBorderThicknessValue(value); + } + + private static Thickness GetBorderThicknessDefaultValue() => Thickness.Empty; + + [GeneratedDependencyProperty(ChangedCallbackName = nameof(OnBorderThicknessPropertyChanged))] + public static DependencyProperty BorderThicknessProperty { get; } = CreateBorderThicknessProperty(); + + private void OnBorderThicknessPropertyChanged(Thickness oldValue, Thickness newValue) + { + BorderThicknessInternal = newValue; + OnBorderThicknessChanged(oldValue, newValue); + } + + private Size BorderAndPaddingSize + { + get + { + var border = BorderThickness; + var padding = Padding; + var width = border.Left + border.Right + padding.Left + padding.Right; + var height = border.Top + border.Bottom + padding.Top + padding.Bottom; + return new Size(width, height); + } + } + + #endregion + + #region Padding DependencyProperty + + public Thickness Padding + { + get => GetPaddingValue(); + set => SetPaddingValue(value); + } + + private static Thickness GetPaddingDefaultValue() => Thickness.Empty; + + [GeneratedDependencyProperty(ChangedCallbackName = nameof(OnPaddingPropertyChanged))] + public static DependencyProperty PaddingProperty { get; } = CreatePaddingProperty(); + + private void OnPaddingPropertyChanged(Thickness oldValue, Thickness newValue) + { + PaddingInternal = newValue; + OnPaddingChanged(oldValue, newValue); + } + + #endregion + + #region CornerRadius DependencyProperty + + public CornerRadius CornerRadius + { + get => GetCornerRadiusValue(); + set => SetCornerRadiusValue(value); + } + + private static CornerRadius GetCornerRadiusDefaultValue() => CornerRadius.None; + + [GeneratedDependencyProperty(ChangedCallbackName = nameof(OnCornerRadiusPropertyChanged))] + public static DependencyProperty CornerRadiusProperty { get; } = CreateCornerRadiusProperty(); + + private void OnCornerRadiusPropertyChanged(CornerRadius oldValue, CornerRadius newValue) + { + CornerRadiusInternal = newValue; + OnCornerRadiusChanged(oldValue, newValue); + } + + #endregion #region Orientation DependencyProperty diff --git a/src/Uno.UI/UI/Xaml/FrameworkElementExtensions.cs b/src/Uno.UI/UI/Xaml/FrameworkElementExtensions.cs index 77aac7e0c70b..c5d1e35bc816 100644 --- a/src/Uno.UI/UI/Xaml/FrameworkElementExtensions.cs +++ b/src/Uno.UI/UI/Xaml/FrameworkElementExtensions.cs @@ -228,6 +228,14 @@ internal static bool TryGetPadding(this IFrameworkElement frameworkElement, out padding = sp.Padding; return true; + case RelativePanel rp: + padding = rp.Padding; + return true; + + case Microsoft.UI.Xaml.Controls.LayoutPanel lp: + padding = lp.Padding; + return true; + case Control c: padding = c.Padding; return true; @@ -240,10 +248,6 @@ internal static bool TryGetPadding(this IFrameworkElement frameworkElement, out padding = b.Padding; return true; - case Panel p: - padding = p.Padding; - return true; - case ItemsPresenter ip: padding = ip.Padding; return true; @@ -269,6 +273,14 @@ internal static bool TrySetPadding(this IFrameworkElement frameworkElement, Thic sp.Padding = padding; return true; + case RelativePanel rp: + rp.Padding = padding; + return true; + + case Microsoft.UI.Xaml.Controls.LayoutPanel lp: + lp.Padding = padding; + return true; + case Control c: c.Padding = padding; return true; @@ -280,10 +292,6 @@ internal static bool TrySetPadding(this IFrameworkElement frameworkElement, Thic case Border b: b.Padding = padding; return true; - - case Panel p: - p.Padding = padding; - return true; } return false; @@ -301,6 +309,14 @@ internal static bool TryGetBorderThickness(this IFrameworkElement frameworkEleme borderThickness = sp.BorderThickness; return true; + case RelativePanel rp: + borderThickness = rp.BorderThickness; + return true; + + case Microsoft.UI.Xaml.Controls.LayoutPanel lp: + borderThickness = lp.BorderThickness; + return true; + case Control c: borderThickness = c.BorderThickness; return true; @@ -312,10 +328,6 @@ internal static bool TryGetBorderThickness(this IFrameworkElement frameworkEleme case Border b: borderThickness = b.BorderThickness; return true; - - case Panel p: - borderThickness = p.BorderThickness; - return true; } borderThickness = default; @@ -334,6 +346,14 @@ internal static bool TrySetBorderThickness(this IFrameworkElement frameworkEleme sp.BorderThickness = borderThickness; return true; + case RelativePanel rp: + rp.BorderThickness = borderThickness; + return true; + + case Microsoft.UI.Xaml.Controls.LayoutPanel lp: + lp.BorderThickness = borderThickness; + return true; + case Control c: c.BorderThickness = borderThickness; return true; @@ -345,10 +365,6 @@ internal static bool TrySetBorderThickness(this IFrameworkElement frameworkEleme case Border b: b.BorderThickness = borderThickness; return true; - - case Panel p: - p.BorderThickness = borderThickness; - return true; } return false; @@ -366,6 +382,14 @@ internal static bool TryGetCornerRadius(this IFrameworkElement frameworkElement, cornerRadius = sp.CornerRadius; return true; + case RelativePanel rp: + cornerRadius = rp.CornerRadius; + return true; + + case Microsoft.UI.Xaml.Controls.LayoutPanel lp: + cornerRadius = lp.CornerRadius; + return true; + case Control c: cornerRadius = c.CornerRadius; return true; @@ -377,10 +401,6 @@ internal static bool TryGetCornerRadius(this IFrameworkElement frameworkElement, case Border b: cornerRadius = b.CornerRadius; return true; - - case Panel p: - cornerRadius = p.CornerRadius; - return true; } cornerRadius = default;