如何使用正确的 Windows 系统颜色?

发布于 2024-10-19 10:04:58 字数 408 浏览 1 评论 0原文

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

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

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

Windows 7 通知区域弹出

I want to use XAML to style a WPF button to look like the "Mixer" and "Change date and time settings..." text of these Windows 7 Notification area flyouts.

Does a property of SystemColors define that color? Which?

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

Windows 7 Notification area flyout

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

独自←快乐 2024-10-26 10:04:58

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

我创建了一个小实用程序来可视化这些颜色。

接口

System.Windows.SystemColors

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> 
                             
                             
                             
                    </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; }
    }
}

The best method I've found is experimentation and guessing.

I created a little utility to visualize these colors.

Interface

System.Windows.SystemColors

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> 
                             
                             
                             
                    </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; }
    }
}
甲如呢乙后呢 2024-10-26 10:04:58

查看此 SystemColors 参考,特别是 Aero 主题颜色

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

Check out this SystemColors reference, and specifically the Aero Theme colors.

It's not obvious which color name that text would use, but trying to eyeball it, it looks like HighlightBrush or MenuHighlightBrush could be candidates...

长亭外,古道边 2024-10-26 10:04:58

用肉眼比较颜色是非常困难的!

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

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

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

笔记:
使用滴管工具单击​​后,您可能需要选择“编辑颜色”才能查看实际的颜色值。反正win7下也可以。

It's very hard to compare colours by eye!

If you take a screen shot (Prt Scr button on your keyboard) you can then paste it into mspaint and use the eye dropper to get the actual colour values.

Tricky on the aliased text, but I read the colour of the text in the screenshot to be R,G,B=0,102,204 and HotTrackColor to be R,G,B = 0,102,203

As I say, the difference could be due to the aliasing on the text.

Note:
After clicking with the Eye Dropper Tool you might need to cilck "Edit colours" to see the actual colour values. You do in win7 anyway.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文