【问题标题】:how to change to string color name from System.Windows.SystemColors.WindowTextBrushKey? [duplicate]如何从 System.Windows.SystemColors.WindowTextBrushKey 更改为字符串颜色名称? [复制]
【发布时间】:2019-07-18 19:46:46
【问题描述】:

有没有办法从后面的 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
       }

【问题讨论】:

标签: c# wpf systemcolors high-contrast


【解决方案1】:

这取决于。 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;
}

【讨论】:

    猜你喜欢
    • 2014-10-12
    • 1970-01-01
    • 1970-01-01
    • 2018-12-21
    • 2020-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多