Skip to content

Commit

Permalink
reorder methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward Miller committed Sep 14, 2024
1 parent 21ab682 commit 9441eaf
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions Maui.DataGrid/DataGridHeaderRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/// <inheritdoc/>
protected override void OnBindingContextChanged()
{
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
}

0 comments on commit 9441eaf

Please sign in to comment.