From f0777a42b919f2c6944fcdf89f71b72442e05280 Mon Sep 17 00:00:00 2001 From: zii-dmg Date: Fri, 26 Apr 2024 13:06:41 +0300 Subject: [PATCH] Grid fixes (#15516) * Fixed ShowGridLines = false crash Fixed "System.InvalidOperationException: 'The control GridLinesRenderer already has a visual parent Grid (Name = grid) while trying to add it as a child of Grid (Name = grid).'" when set ShowGridLines = false and resize. * Fixed grid lines renderer (fixes ShowGridLines binding) When changing ShowGridLines property GridLinesRenderer is not updating (create/remove/set bounds). Need to call InvalidateArrange -> ArrangeOverride -> EnsureGridLinesRenderer. --- src/Avalonia.Controls/Grid.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Controls/Grid.cs b/src/Avalonia.Controls/Grid.cs index db145b4348..2e745cd364 100644 --- a/src/Avalonia.Controls/Grid.cs +++ b/src/Avalonia.Controls/Grid.cs @@ -2325,7 +2325,7 @@ namespace Avalonia.Controls if ((!ShowGridLines) && (_gridLinesRenderer != null)) { - VisualChildren.Add(_gridLinesRenderer); + VisualChildren.Remove(_gridLinesRenderer); _gridLinesRenderer = null; } @@ -2357,7 +2357,7 @@ namespace Avalonia.Controls if (grid._extData != null // trivial grid is 1 by 1. there is no grid lines anyway && grid.ListenToNotifications) { - grid.InvalidateVisual(); + grid.InvalidateArrange(); } grid.SetFlags((bool)e.NewValue!, Flags.ShowGridLinesPropertyValue);