Repository: AvaloniaUI/Avalonia
File: src/Avalonia.Controls/GridSplitter.cs (C#)

Code before:
                layer.Children.Remove(_resizeData.Adorner);
            }
        }

        private Grid? GetParentGrid()
        {
            var grid = Parent as Grid;
            if (grid is not null)
            {
                return grid;
            }

            // When GridSplitter is used inside an ItemsControl with Grid as
            // its ItemsPanel, its immediate parent is usually a ItemsControl or ContentPresenter.
            switch (Parent)
            {
                case ItemsControl itemsControl:
                {
                    if (itemsControl.ItemsPanelRoot is Grid itemsPanelGrid)
                    {
                        grid = itemsPanelGrid;
                    }

                    break;
                }
                case ContentPresenter { Parent: ItemsControl presenterItemsControl }:
                {
                    if (presenterItemsControl.ItemsPanelRoot is Grid itemsPanelGrid)
                    {
                        grid = itemsPanelGrid;
                    }

                    break;
                }
            }

            return grid;
        }

        /// <summary>
        /// Initialize the data needed for resizing.
        /// </summary>
        private void InitializeData(bool showsPreview)
        {
            // If not in a grid or can't resize, do nothing.
            var grid = GetParentGrid();

            if (grid != null)
            {
                GridResizeDirection resizeDirection = GetEffectiveResizeDirection();


Review comment (refactor):
I'm not sure I like having such a specialization here. It seems a bit odd to have `GridSplitter` know about every possible hierarchy it could be in.

That said, introducing some abstraction just for this purpose sounds like over engineering...

Code after:
                layer.Children.Remove(_resizeData.Adorner);
            }
        }

        /// <summary>
        /// Initialize the data needed for resizing.
        /// </summary>
        private void InitializeData(bool showsPreview)
        {
            // If not in a grid or can't resize, do nothing.
            var grid = GetParentGrid();

            if (grid != null)
            {
                GridResizeDirection resizeDirection = GetEffectiveResizeDirection();

                // Setup data used for resizing.
                _resizeData = new ResizeData
                {
                    Grid = grid,
                    ShowsPreview = showsPreview,
                    ResizeDirection = resizeDirection,
                    SplitterLength = Math.Min(Bounds.Width, Bounds.Height),
                    ResizeBehavior = GetEffectiveResizeBehavior(resizeDirection),
                    Scaling = (VisualRoot as ILayoutRoot)?.LayoutScaling ?? 1,
                };

                // Store the rows and columns to resize on drag events.
                if (!SetupDefinitionsToResize())
                {
                    // Unable to resize, clear data.
                    _resizeData = null;
                    return;
                }

                // Setup the preview in the adorner if ShowsPreview is true.
                SetupPreviewAdorner();
            }
        }

        /// <summary>
        /// Returns true if GridSplitter can resize rows/columns.
        /// </summary>
        private bool SetupDefinitionsToResize()
        {
            // Get properties values from ContentPresenter if Grid it's used in ItemsControl as ItemsPanel otherwise directly from GridSplitter.
            var sourceControl = GetPropertiesValueSource();
            int gridSpan = sourceControl.GetValue(_resizeData!.ResizeDirection == GridResizeDirection.Columns ?
                Grid.ColumnSpanProperty :
                Grid.RowSpanProperty);