加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

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

发布时间:2020-12-13 20:13:11 所属栏目:Windows 来源:网络整理
导读:我想使用XAML来设计 WPF按钮,看起来像这些 Windows 7通知区域弹出窗口中的“混音器”和“更改日期和时间设置…”文本. SystemColors的属性是否定义了该颜色?哪一个? Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.????}}"
我想使用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; }
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读