浏览代码

Invalidate parent grid when property changes on DefBase.
Link ActualWidth/Height setters to their parent GetFinalColumnDefinitionWidth/GetFinalRowDefinitionWidth

Jumar Macato 6 年之前
父节点
当前提交
c7a372d0b6

+ 1 - 5
src/Avalonia.Controls/ColumnDefinition.cs

@@ -55,11 +55,7 @@ namespace Avalonia.Controls
         /// <summary>
         /// <summary>
         /// Gets the actual calculated width of the column.
         /// Gets the actual calculated width of the column.
         /// </summary>
         /// </summary>
-        public double ActualWidth
-        {
-            get;
-            internal set;
-        }
+        public double ActualWidth => Parent?.GetFinalColumnDefinitionWidth(Index) ?? 0d;
 
 
         /// <summary>
         /// <summary>
         /// Gets or sets the maximum width of the column in DIPs.
         /// Gets or sets the maximum width of the column in DIPs.

+ 19 - 14
src/Avalonia.Controls/DefinitionBase.cs

@@ -85,6 +85,15 @@ namespace Avalonia.Controls
             }
             }
         }
         }
 
 
+        protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs e)
+        {
+            if(e.Property.PropertyType == typeof(GridLength)
+             || e.Property.PropertyType == typeof(double))
+                OnUserSizePropertyChanged(e);
+                
+            base.OnPropertyChanged(e);
+        }
+
         /// <summary>
         /// <summary>
         /// Callback to notify about exitting model tree.
         /// Callback to notify about exitting model tree.
         /// </summary>
         /// </summary>
@@ -108,7 +117,7 @@ namespace Avalonia.Controls
             LayoutWasUpdated = true;
             LayoutWasUpdated = true;
 
 
             //  defer verification for shared definitions
             //  defer verification for shared definitions
-            if (_sharedState != null)   {   _sharedState.EnsureDeferredValidation(grid);    }
+            if (_sharedState != null) { _sharedState.EnsureDeferredValidation(grid); }
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -135,32 +144,28 @@ namespace Avalonia.Controls
         /// <remarks>
         /// <remarks>
         /// This method needs to be internal to be accessable from derived classes.
         /// This method needs to be internal to be accessable from derived classes.
         /// </remarks>
         /// </remarks>
-        internal static void OnUserSizePropertyChanged(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e)
+        internal void OnUserSizePropertyChanged(AvaloniaPropertyChangedEventArgs e)
         {
         {
-            DefinitionBase definition = (DefinitionBase) d;
-
-            if (definition.InParentLogicalTree)
+            if (InParentLogicalTree)
             {
             {
-                if (definition._sharedState != null)
+                if (_sharedState != null)
                 {
                 {
-                    definition._sharedState.Invalidate();
+                    _sharedState.Invalidate();
                 }
                 }
                 else
                 else
                 {
                 {
-                    Grid parentGrid = (Grid) definition.Parent;
-
-                    if (((GridLength) e.OldValue).GridUnitType != ((GridLength) e.NewValue).GridUnitType)
+                    if (((GridLength)e.OldValue).GridUnitType != ((GridLength)e.NewValue).GridUnitType)
                     {
                     {
-                        parentGrid.Invalidate();
+                        Parent.Invalidate();
                     }
                     }
                     else
                     else
-                    {   
-                        parentGrid.InvalidateMeasure();     
+                    {
+                        Parent.InvalidateMeasure();
                     }
                     }
                 }
                 }
             }
             }
         }
         }
-
+        
         /// <summary>
         /// <summary>
         /// <see cref="AvaloniaProperty.ValidateValueCallback"/>
         /// <see cref="AvaloniaProperty.ValidateValueCallback"/>
         /// </summary>
         /// </summary>

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

@@ -656,11 +656,8 @@ namespace Avalonia.Controls
                     }
                     }
 
 
                     //  update render bound on grid lines renderer visual
                     //  update render bound on grid lines renderer visual
-                    GridLinesRenderer gridLinesRenderer = EnsureGridLinesRenderer();
-                    if (gridLinesRenderer != null)
-                    {
-                        gridLinesRenderer.UpdateRenderBounds(arrangeSize);
-                    }
+                    var gridLinesRenderer = EnsureGridLinesRenderer();
+                    gridLinesRenderer?.UpdateRenderBounds(arrangeSize);
                 }
                 }
             }
             }
             finally
             finally
@@ -956,6 +953,7 @@ namespace Avalonia.Controls
                 for(int i = 0; i < extData.DefinitionsU.Count;i++)
                 for(int i = 0; i < extData.DefinitionsU.Count;i++)
                 {
                 {
                     var definition = extData.DefinitionsU[i];
                     var definition = extData.DefinitionsU[i];
+                    definition.Parent = this;
                     definition.Index = i;
                     definition.Index = i;
                     definition.OnEnterParentTree();
                     definition.OnEnterParentTree();
                 }
                 }
@@ -1009,6 +1007,7 @@ namespace Avalonia.Controls
                 for(int i = 0; i < extData.DefinitionsV.Count;i++)
                 for(int i = 0; i < extData.DefinitionsV.Count;i++)
                 {
                 {
                     var definition = extData.DefinitionsV[i];
                     var definition = extData.DefinitionsV[i];
+                    definition.Parent = this;
                     definition.Index = i;
                     definition.Index = i;
                     definition.OnEnterParentTree();
                     definition.OnEnterParentTree();
                 }
                 }
@@ -4075,6 +4074,7 @@ namespace Avalonia.Controls
             internal void UpdateRenderBounds(Size arrangeSize)
             internal void UpdateRenderBounds(Size arrangeSize)
             {
             {
                 _lastArrangeSize = arrangeSize;
                 _lastArrangeSize = arrangeSize;
+                this.InvalidateMeasure();
                 this.InvalidateVisual();
                 this.InvalidateVisual();
             }
             }
 
 

+ 1 - 5
src/Avalonia.Controls/RowDefinition.cs

@@ -55,11 +55,7 @@ namespace Avalonia.Controls
         /// <summary>
         /// <summary>
         /// Gets the actual calculated height of the row.
         /// Gets the actual calculated height of the row.
         /// </summary>
         /// </summary>
-        public double ActualHeight
-        {
-            get;
-            internal set;
-        }
+        public double ActualHeight => Parent?.GetFinalRowDefinitionHeight(Index) ?? 0d;
 
 
         /// <summary>
         /// <summary>
         /// Gets or sets the maximum height of the row in DIPs.
         /// Gets or sets the maximum height of the row in DIPs.