Skip to content

Commit

Permalink
Merge pull request #2480 from cwensley/curtis/wpf-use-theme-colors-fo…
Browse files Browse the repository at this point in the history
…r-custom-cell

Wpf: Allow theme resources to override colors used for CustomCellEventArgs.CellTextColor
  • Loading branch information
cwensley authored May 18, 2023
2 parents 390aa40 + 505b12d commit fbca3aa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Eto.Wpf/Forms/Cells/CustomCellHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public void SetSelected(swc.DataGridCell cell)
var selected = cell.IsSelected;
IsSelected = selected;
var focused = grid?.IsKeyboardFocusWithin != false;
CellTextColor = selected && focused ? Eto.Drawing.SystemColors.HighlightText : Eto.Drawing.SystemColors.ControlText;
CellTextColor = selected && focused
? (cell.GetResourceColor(sw.SystemColors.HighlightTextColorKey, sw.SystemColors.HighlightTextBrushKey) ?? Eto.Drawing.SystemColors.HighlightText)
: (cell.GetResourceColor(sw.SystemColors.ControlTextColorKey, sw.SystemColors.ControlTextBrushKey) ?? Eto.Drawing.SystemColors.ControlText);
}
public void SetRow(sw.FrameworkElement element)
{
Expand Down
22 changes: 22 additions & 0 deletions src/Eto.Wpf/WpfConversions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -942,5 +942,27 @@ public static swm.PixelFormat GetNonPremultipliedFormat(this swm.PixelFormat for
return swm.PixelFormats.Rgba64;
return format;
}

public static Color? GetResourceColor(this sw.FrameworkElement cell, sw.ResourceKey key)
{
var res = cell.TryFindResource(key);
if (res is swm.SolidColorBrush brush)
return brush.ToEtoColor();
if (res is swm.Color color)
return color.ToEto();
return null;
}

public static Color? GetResourceColor(this sw.FrameworkElement cell, params sw.ResourceKey[] keys)
{
for (int i = 0; i < keys.Length; i++)
{
sw.ResourceKey key = keys[i];
var value = GetResourceColor(cell, key);
if (value != null)
return value;
}
return null;
}
}
}

0 comments on commit fbca3aa

Please sign in to comment.