c# - 如何从 System.Windows.SystemColors.WindowTextBrushKey 更改为字符串颜色名称?
问题描述
有没有办法从后面的 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
}
解决方案
这取决于。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;
}
推荐阅读
- android - DatabaseReference 'setValue' Android Studio 显示错误
- android - 收到错误 android.util.SuperNotCalledException: Activity {} 没有调用 super.onCreate()
- asp.net - 文本未在材料 UI 核心中选择下拉列表的中心垂直对齐
- python - 如何调整我的神经网络以避免过度拟合 mnist 数据集?
- r - 如何分别标记所有组记录?
- python - Pygame 错误,音乐无法正常播放,因为它只是循环开始部分
- ruby-on-rails - 在 Rails 配置中获取 Rack/Puma 选项
- javascript - 在 laravel 中使用 ajax 上传文件
- azure - 使用 Function App 的 MSI 连接到主题
- javascript - 如何解决这个 Javascript/CSS 问题?