MaterialDesignInXamlToolkit
MaterialDesignInXamlToolkit copied to clipboard
DataGrid gridlines too thick when background set to Transparent
I think following some of the improvements in #1838 the DataGrid gridlines don't seem to play nicely when the DataGrid background is set to Transparent.
Example when the DataGrid background is set to Transparent:

And when the DataGrid background is set specifically to the brush:

That is interesting. From measuring, it appears that the lines in both screenshots are in fact the same size, however the ones in the transparent case are certainly brighter. Will need to dig into this more to know what is going on.
Can you provide the exact RGB colors you were using for the lines and the backgrounds?
Hi @Keboo , sure it is #3D4C5C. Although this also happens on the demo app in dark theme and its default background.
I believe the issue occurs on the RemoveAlphaBrushConverter. The Transparent background is passed to it as white.
I have worked around this for now by setting DataGrid background to look up the background of its parent control rather than be Transparent.
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
=> values[0] is SolidColorBrush brush
? new SolidColorBrush(RgbaToRgb(brush.Color, values[1]))
: Binding.DoNothing;
private static Color RgbaToRgb(Color rgba, object background)
{
var backgroundColor = background switch
{
Color c => c,
SolidColorBrush b => b.Color,
_ => Colors.White
};
var alpha = (double) rgba.A / byte.MaxValue;
var alphaReverse = 1 - alpha;
return Color.FromRgb(
(byte) (alpha * rgba.R + alphaReverse * backgroundColor.R),
(byte) (alpha * rgba.G + alphaReverse * backgroundColor.G),
(byte) (alpha * rgba.B + alphaReverse * backgroundColor.B)
);
@yosefmah Thanks for the information, that is very helpful.
I added the RemoveAlphaBrushConverter to work around a problem. Here is HorizontalGridLinesBrush without opacity.

here with opacity (set directly to MaterialDesignDivider)

You can notice, that the actual data cells have stronger lines. It seems that WPF renders the horizontal grid lines doubled.
That is the reason why the grid line is drawn without opacity. Which makes it necessary to get the background color. And Transparent breaks this obviously.