开发者

How do I use the correct Windows system colors?

开发者 https://www.devze.com 2023-02-13 04:06 出处:网络
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.

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.????}}" />

How do I use the correct Windows system colors?


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

I created a little utility to visualize these colors.

Interface

How do I use the correct Windows system colors?

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


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...


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消