如何使用正确的 Windows 系统颜色? [英] How do I use the correct Windows system colors?

查看:31
本文介绍了如何使用正确的 Windows 系统颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 XAML 为 WPF 按钮设置样式,使其看起来像这些 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.

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

Does a property of SystemColors define that color? Which?

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

推荐答案

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

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

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

I created a little utility to visualize these colors.

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

这篇关于如何使用正确的 Windows 系统颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆