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

前端之家收集整理的这篇文章主要介绍了wpf – 如何使用正确的Windows系统颜色?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想使用XAML来设计 WPF按钮,看起来像这些 Windows 7通知区域弹出窗口中的“混音器”和“更改日期和时间设置…”文本.

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

<Setter Property="Foreground"
        Value="{DynamicResource {x:Static 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> 
                        &#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);
                    cn.Name = i.Name;
                    l.Add(cn);
                }
            }

            SystemColorsList.DataContext = l;
        }
    }

    class ColorAndName
    {
        public Color Color { get; set; }
        public string Name { get; set; }
    }
}
原文链接:https://www.f2er.com/windows/371195.html

猜你在找的Windows相关文章