From 505ed6b0cf9cacb107ab6baedae45c2d2692b24b Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Mon, 27 May 2019 11:15:04 +0800 Subject: [PATCH] Replace per-property class handlers with `AffectsParentMeasure<>`; Fix `GridLinesRenderer`. --- src/Avalonia.Controls/GridWPF.cs | 39 ++++++++------------------------ 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/src/Avalonia.Controls/GridWPF.cs b/src/Avalonia.Controls/GridWPF.cs index 119c94c6e0..f1cf1e8f5b 100644 --- a/src/Avalonia.Controls/GridWPF.cs +++ b/src/Avalonia.Controls/GridWPF.cs @@ -38,7 +38,6 @@ namespace Avalonia.Controls internal bool ColumnDefinitionsDirty; internal bool RowDefinitionsDirty; - // index of the first cell in first cell group internal int CellGroup1; @@ -77,11 +76,7 @@ namespace Avalonia.Controls static Grid() { ShowGridLinesProperty.Changed.AddClassHandler(OnShowGridLinesPropertyChanged); - - ColumnProperty.Changed.AddClassHandler(OnCellAttachedPropertyChanged); - ColumnSpanProperty.Changed.AddClassHandler(OnCellAttachedPropertyChanged); - RowProperty.Changed.AddClassHandler(OnCellAttachedPropertyChanged); - RowSpanProperty.Changed.AddClassHandler(OnCellAttachedPropertyChanged); + AffectsParentMeasure(ColumnProperty, ColumnSpanProperty, RowProperty, RowSpanProperty); } /// @@ -521,12 +516,12 @@ namespace Avalonia.Controls cell.Arrange(cellRect); } - // // update render bound on grid lines renderer visual - // var gridLinesRenderer = EnsureGridLinesRenderer(); - // if (gridLinesRenderer != null) - // { - // gridLinesRenderer.UpdateRenderBounds(arrangeSize); - // } + // update render bound on grid lines renderer visual + var gridLinesRenderer = EnsureGridLinesRenderer(); + if (gridLinesRenderer != null) + { + gridLinesRenderer.UpdateRenderBounds(arrangeSize); + } } } finally @@ -2144,22 +2139,7 @@ namespace Avalonia.Controls if (!grid.IsTrivialGrid // trivial grid is 1 by 1. there is no grid lines anyway && grid.ListenToNotifications) { - grid.InvalidateVisual(); - } - } - - private static void OnCellAttachedPropertyChanged(Visual child, AvaloniaPropertyChangedEventArgs e) - { - if (child != null) - { - var grid = child.GetVisualParent() as Grid; - if (grid != null - && !grid.IsTrivialGrid - && grid.ListenToNotifications) - { - grid.CellsStructureDirty = true; - grid.InvalidateMeasure(); - } + grid.Invalidate(); } } @@ -2692,7 +2672,7 @@ namespace Avalonia.Controls /// /// Helper to render grid lines. /// - internal class GridLinesRenderer : Visual + internal class GridLinesRenderer : Control { /// /// Static initialization @@ -2769,6 +2749,7 @@ namespace Avalonia.Controls lastArrangeSize = arrangeSize; this.InvalidateVisual(); } + private static Size lastArrangeSize; private const double c_dashLength = 4.0; // private const double c_penWidth = 1.0; //