Browse Source

Inherit SharedSize scopes to child grids.

Jumar Macato 6 years ago
parent
commit
2310dab605
2 changed files with 24 additions and 7 deletions
  1. 3 2
      src/Avalonia.Controls/Grid/DefinitionBase.cs
  2. 21 5
      src/Avalonia.Controls/Grid/Grid.cs

+ 3 - 2
src/Avalonia.Controls/Grid/DefinitionBase.cs

@@ -19,6 +19,7 @@ namespace Avalonia.Controls
         {
             SharedSizeGroupProperty.Changed.AddClassHandler<DefinitionBase>(OnSharedSizeGroupPropertyChanged);
         }
+        
         internal bool UseSharedMinimum { get; set; }
         internal bool LayoutWasUpdated { get; set; }
         
@@ -59,10 +60,10 @@ namespace Avalonia.Controls
         {
             if (_sharedState == null & 
                 SharedSizeGroup != null & 
-                Parent?.sharedSizeScope != null & 
+                Parent?.PrivateSharedSizeScope != null & 
                 !_successUpdateSharedScope)
             {
-                _privateSharedSizeScope = Parent.sharedSizeScope;
+                _privateSharedSizeScope = Parent.PrivateSharedSizeScope;
                 _sharedState = _privateSharedSizeScope.EnsureSharedState(SharedSizeGroup);
                 _sharedState.AddMember(this);
                 _successUpdateSharedScope = true;

+ 21 - 5
src/Avalonia.Controls/Grid/Grid.cs

@@ -86,7 +86,12 @@ namespace Avalonia.Controls
         private RowDefinitions _rowDefinitions;
         private DefinitionBase[] _definitionsU = new DefinitionBase[1] { new ColumnDefinition() };
         private DefinitionBase[] _definitionsV = new DefinitionBase[1] { new RowDefinition() };
-        internal SharedSizeScope sharedSizeScope;
+
+        internal SharedSizeScope PrivateSharedSizeScope
+        {
+            get { return GetPrivateSharedSizeScope(this); }
+            set { SetPrivateSharedSizeScope(this, value); }
+        }
 
         // 5 is an arbitrary constant chosen to end the measure loop
         private const int _layoutLoopMaxCount = 5;
@@ -197,11 +202,11 @@ namespace Avalonia.Controls
         {
             if ((bool)e.NewValue)
             {
-                grid.sharedSizeScope = new SharedSizeScope();
+                grid.PrivateSharedSizeScope = new SharedSizeScope();
             }
             else
             {
-                grid.sharedSizeScope = null;
+                grid.PrivateSharedSizeScope = null;
             }
         }
 
@@ -236,6 +241,9 @@ namespace Avalonia.Controls
         public static readonly AttachedProperty<bool> IsSharedSizeScopeProperty =
             AvaloniaProperty.RegisterAttached<Grid, Control, bool>("IsSharedSizeScope", false);
 
+        internal static readonly AttachedProperty<SharedSizeScope> PrivateSharedSizeScopeProperty =
+            AvaloniaProperty.RegisterAttached<Grid, Control, SharedSizeScope>("PrivateSharedSizeScope", null, inherits: true);
+
         /// <summary>
         /// Defines the <see cref="ShowGridLines"/> property.
         /// </summary>
@@ -409,13 +417,21 @@ namespace Avalonia.Controls
         /// <summary>
         /// Sets the value of the IsSharedSizeScope attached property for a control.
         /// </summary>
-        /// <param name="element">The control.</param>
-        /// <returns>The control's IsSharedSizeScope value.</returns>
         public static void SetIsSharedSizeScope(AvaloniaObject element, bool value)
         {
             element.SetValue(IsSharedSizeScopeProperty, value);
         }
 
+        internal static SharedSizeScope GetPrivateSharedSizeScope(AvaloniaObject element)
+        {
+            return element.GetValue(PrivateSharedSizeScopeProperty);
+        }
+
+        internal static void SetPrivateSharedSizeScope(AvaloniaObject element, SharedSizeScope value)
+        {
+            element.SetValue(PrivateSharedSizeScopeProperty, value);
+        }
+
         /// <summary>
         /// Sets the value of the Column attached property for a control.
         /// </summary>