【问题标题】:How do I use the correct Windows system colors?如何使用正确的 Windows 系统颜色?
【发布时间】:2011-07-02 22:34:48
【问题描述】:

我想使用 XAML 来设置 WPF 按钮的样式,使其看起来像这些 Windows 7 通知区域弹出按钮的“混合器”和“更改日期和时间设置...”文本。

SystemColors 的属性是否定义了该颜色?哪个?

<Setter Property="Foreground"
        Value="{DynamicResource {x:Static SystemColors.????}}" />

【问题讨论】:

  • SystemColors 类对我有用。您可以像这样绑定到它:{x:Static SystemColors.HighlightBrushKey}。有什么不适合您的具体内容吗?
  • 它有效。我只需要知道如何选择正确的颜色。 “HighlightBrushKey”很接近,但不是正确的蓝色阴影。
  • 从实验来看,似乎是HotTrack。在我的系统上两者都是#0066CC。我希望有更好的方法来解决这个问题并确定。 MSDN 将其描述为“用于指定热跟踪项目的颜色”。谢谢,微软!

标签: wpf windows xaml styles


【解决方案1】:

看看这个SystemColors reference,特别是Aero Theme colors

不清楚该文本将使用哪种颜色名称,但尝试观察它,看起来 HighlightBrushMenuHighlightBrush 可能是候选...

【讨论】:

  • 从实验来看,似乎是HotTrack。
【解决方案2】:

您可能想阅读Aero Theme aesthetics guidelines

【讨论】:

    【解决方案3】:

    我发现最好的方法是实验和猜测。

    我创建了一个小工具来可视化这些颜色。

    界面

    XAML

    <Window x:Class="SystemColors1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="System.Windows.SystemColors" Height="350" Width="525">
        <Window.Resources>
            <DataTemplate x:Key="CellColor">
                <DockPanel>
                    <TextBlock>
                        <TextBlock.Background>
                            <SolidColorBrush Color="{Binding Path=Color}" />
                        </TextBlock.Background>
                        <TextBlock.Text> 
                            &#160;&#160;&#160;&#160;&#160;
                            &#160;&#160;&#160;&#160;&#160;
                            &#160;&#160;&#160;&#160;&#160;
                        </TextBlock.Text>
                    </TextBlock>
                </DockPanel>
            </DataTemplate>
        </Window.Resources>
        <Grid>
            <ListView Grid.Row="1"
                      Name="SystemColorsList"
                      ItemsSource="{Binding}">
                <ListView.View>
                    <GridView AllowsColumnReorder="True">
                        <GridViewColumn CellTemplate="{StaticResource CellColor}"
                                        Header="Color"
                                        Width="Auto"/>
                        <GridViewColumn DisplayMemberBinding="{Binding Path=Name}"
                                        Header="Name"
                                        Width="Auto"/>
                    </GridView>
                </ListView.View>
            </ListView>
        </Grid>
    </Window>
    

    C#

    using System.Collections.Generic;
    using System.Windows;
    using System.Windows.Media;
    using System.Reflection;
    
    namespace SystemColors1
    {
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
    
                List<ColorAndName> l = new List<ColorAndName>();
    
                foreach (PropertyInfo i in typeof(System.Windows.SystemColors).GetProperties())
                {
                    if (i.PropertyType == typeof(Color))
                    {
                        ColorAndName cn = new ColorAndName();
                        cn.Color = (Color)i.GetValue(new Color(), BindingFlags.GetProperty, null, null, null);
                        cn.Name = i.Name;
                        l.Add(cn);
                    }
                }
    
                SystemColorsList.DataContext = l;
            }
        }
    
        class ColorAndName
        {
            public Color Color { get; set; }
            public string Name { get; set; }
        }
    }
    

    【讨论】:

    • 好清单,谢谢。对于其他难以让颜色出现的人(比如我!),在此处列出的名称末尾添加“Key”很重要。例如。 {DynamicResource {x:Static SystemColors.MenuTextColorKey}}
    【解决方案4】:

    很难用肉眼比较颜色!

    如果您拍摄屏幕截图(键盘上的 Prt Scr 按钮),您可以将其粘贴到 mspaint 并使用滴管获取实际颜色值。

    别名文本很棘手,但我读到屏幕截图中文本的颜色为 R,G,B=0,102,204,HotTrackColor 为 R,G,B = 0,102,203

    正如我所说,差异可能是由于文本上的别名。

    注意: 单击滴管工具后,您可能需要单击“编辑颜色”以查看实际颜色值。无论如何,你在win7中都这样做。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-25
      • 1970-01-01
      • 1970-01-01
      • 2012-01-18
      • 1970-01-01
      • 2012-09-17
      相关资源
      最近更新 更多