diff --git a/Maui.DataGrid/DataGridHeaderRow.cs b/Maui.DataGrid/DataGridHeaderRow.cs index af25b71..20ecfed 100644 --- a/Maui.DataGrid/DataGridHeaderRow.cs +++ b/Maui.DataGrid/DataGridHeaderRow.cs @@ -103,29 +103,6 @@ internal void InitializeHeaderRow(bool force = false) ColumnDefinitions.RemoveAfter(DataGrid.Columns.Count); } - private void UpdateBorders() - { - // This approach is a hack to avoid needing a slow Border control. - // The padding constitutes the cell's border thickness. - // And the BackgroundColor constitutes the border color of the cell. - if (DataGrid.HeaderBordersVisible) - { - var borderSize = DataGrid.BorderThickness; - ColumnSpacing = borderSize.Left; - Padding = new(0, borderSize.Top / 2, 0, borderSize.Bottom / 2); - } - else - { - ColumnSpacing = 0; - Padding = 0; - } - } - - private void OnBorderThicknessChanged(object? sender, EventArgs e) - { - UpdateBorders(); - } - /// protected override void OnBindingContextChanged() { @@ -186,6 +163,11 @@ private static bool CanSort(DataGridColumn column) return column.SortingEnabled && column.DataGrid.Columns.Contains(column); } + private void OnBorderThicknessChanged(object? sender, EventArgs e) + { + UpdateBorders(); + } + private void OnColumnsChanged(object? sender, EventArgs e) { InitializeHeaderRow(); @@ -235,5 +217,23 @@ private DataGridCell CreateHeaderCell(DataGridColumn column) return new DataGridCell(cellContent, DataGrid.HeaderBackground, column, false); } + private void UpdateBorders() + { + // This approach is a hack to avoid needing a slow Border control. + // The padding constitutes the cell's border thickness. + // And the BackgroundColor constitutes the border color of the cell. + if (DataGrid.HeaderBordersVisible) + { + var borderSize = DataGrid.BorderThickness; + ColumnSpacing = borderSize.Left; + Padding = new(0, borderSize.Top / 2, 0, borderSize.Bottom / 2); + } + else + { + ColumnSpacing = 0; + Padding = 0; + } + } + #endregion Methods }