how to change to string color name from System.Windows.SystemColors.WindowTextBrushKey?

303 Views Asked by At

Is there some way to get color names such as Red, Black etc. from System.Windows.SystemColors.WindowTextBrushKey in WPF code behind?

       string color = "Black";
       if (System.Windows.SystemParameters.HighContrast)
       {                    
          color = System.Windows.SystemColors.WindowTextBrushKey; // I want to get color from this value
       }
1

There are 1 best solutions below

0
mm8 On

It depends. SystemColors.WindowTextBrush will give you the Brush. You could then check wheter its string representation matches any of the Brushes returned from the static properties the Brushes class:

string color = "Black";
if (System.Windows.SystemParameters.HighContrast)
{
    System.Windows.Media.Brush brush = System.Windows.SystemColors.WindowTextBrush;
    string s = brush.ToString();
    color = typeof(System.Windows.Media.Brushes).GetProperties()
        .FirstOrDefault(p => p.GetValue(null)?
        .ToString() == s)?
        .Name;
}