【发布时间】:2013-11-29 04:51:04
【问题描述】:
我想将按钮的背景颜色更改为系统颜色。就像我正在更改按钮颜色一样
button2.Background = Brushes.Blue;
到蓝色。但是不,我想将颜色更改为系统颜色。
【问题讨论】:
-
有很多不同的系统颜色。你要哪一个?
我想将按钮的背景颜色更改为系统颜色。就像我正在更改按钮颜色一样
button2.Background = Brushes.Blue;
到蓝色。但是不,我想将颜色更改为系统颜色。
【问题讨论】:
您可以从 System.Windows.SystemColors 获取系统颜色
button2.Background = System.Windows.SystemColors.MenuHighlightBrush;
WPF 背景的类型是 System.Windows.Media.Brush。您可以像这样设置另一种颜色:
// using System.Windows.Media;
button2.Background = Brushes.White;
button2.Background = new SolidColorBrush(Color.White);
button2.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0, 0);
【讨论】:
希望对你有帮助
<Button
Background="{DynamicResource {x:Static SystemColors.DesktopBrushKey}}"
Content="Hello, World!" />
【讨论】:
你可以试试这样的:
button2.Background = SystemColors.ActiveCaptionBrush;
SystemColors 属于 System.Windows 命名空间。
【讨论】:
背景是画笔类型。但是您可以使用系统颜色创建一个实心画笔并使用它。
SolidBrush systemColorBrush = new SolidBrush(systemColor); // Create SolidBrush from color
button2.Background = systemColorBrush;
【讨论】: