Skip to content

Commit

Permalink
ensure text is inverse of active background color
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward Miller committed Apr 18, 2024
1 parent c1f116a commit b596ca5
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Maui.DataGrid/DataGridRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,20 @@ private void UpdateColors()
return;
}

CellBackgroundColor = DataGrid.SelectionMode != SelectionMode.None && _wasSelected
var isSelected = DataGrid.SelectionMode != SelectionMode.None && _wasSelected;

CellBackgroundColor = isSelected
? DataGrid.ActiveRowColor
: DataGrid.RowsBackgroundColorPalette.GetColor(rowIndex, BindingContext);
CellTextColor = DataGrid.RowsTextColorPalette.GetColor(rowIndex, BindingContext);
CellTextColor = isSelected
? InverseColor(DataGrid.ActiveRowColor)
: DataGrid.RowsTextColorPalette.GetColor(rowIndex, BindingContext);
}

private static Color InverseColor(Color color)
{
var brightness = (0.299 * color.Red) + (0.587 * color.Green) + (0.114 * color.Blue);
return brightness < 0.5 ? Colors.White : Colors.Black;
}

/// <inheritdoc/>
Expand Down

0 comments on commit b596ca5

Please sign in to comment.