The Background property is of type Brush, so it can be a SolidColorBrush
or a GradientBrush
and so on.
I think you need to distinguish between the various types and perform the correct comparison.
For example:
if(Button.Background is SolidColorBrush)
{
bool isRed = ((SolidColorBrush)Button.Background).Color == Colors.Red;
}
else if (Button.Background is GradientBrush)
{
...
}
To compare a to a specific hexadecimal color:
bool flag = ((SolidColorBrush)Button.Background).Color ==
(Color)ColorConverter.ConvertFromString("#FF008F06");