瀏覽代碼

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.
zii-dmg 1 年之前
父節點
當前提交
f0777a42b9
共有 1 個文件被更改,包括 2 次插入2 次删除
  1. 2 2
      src/Avalonia.Controls/Grid.cs

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

@@ -2325,7 +2325,7 @@ namespace Avalonia.Controls
 
 
             if ((!ShowGridLines) && (_gridLinesRenderer != null))
             if ((!ShowGridLines) && (_gridLinesRenderer != null))
             {
             {
-                VisualChildren.Add(_gridLinesRenderer);
+                VisualChildren.Remove(_gridLinesRenderer);
                 _gridLinesRenderer = null;
                 _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
             if (grid._extData != null    // trivial grid is 1 by 1. there is no grid lines anyway
                 && grid.ListenToNotifications)
                 && grid.ListenToNotifications)
             {
             {
-                grid.InvalidateVisual();
+                grid.InvalidateArrange();
             }
             }
 
 
             grid.SetFlags((bool)e.NewValue!, Flags.ShowGridLinesPropertyValue);
             grid.SetFlags((bool)e.NewValue!, Flags.ShowGridLinesPropertyValue);