0

有没有办法从后面的 WPF 代码中的System.Windows.SystemColors.WindowTextBrushKey获取颜色名称,如红色、黑色等?

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

1 回答 1

0

这取决于。SystemColors.WindowTextBrush会给你Brush。然后,您可以检查它的字符串表示是否匹配Brushes从类的静态属性返回的任何内容Brushes

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;
}
于 2019-07-18T11:46:46.043 回答