该 SystemColors 类提供对系统画笔和颜色(例如 ControlBrush, ControlBrushKey和 DesktopBrush)的访问。 系统画笔是一个对象,用指定的系统颜色绘制SolidColorBrush区域。 系统画笔总是产生实色填充,它不能用于实现渐变效果。
可以将系统画笔用作静态资源或动态资源。 如果希望画笔在应用程序运行时系统画笔更改时自动更新,请使用动态资源;否则,请使用静态资源。 SystemColors 类包含遵循严格命名约定的各种静态属性:
<系统颜色>画笔
获取对 SolidColorBrush 指定系统颜色的静态引用。
*<SystemColor>*BrushKey
获取对指定系统颜色SolidColorBrush的动态引用。
*<系统颜色>*颜色
获取对 Color 指定系统颜色结构的静态引用。
*<系统颜色>*颜色键
获取对 Color 指定系统颜色结构的动态引用。
系统颜色是一个可以用于配置画笔的Color 结构。 例如,可以通过使用系统颜色设置 Color 对象的渐变断点的属性来创建渐变。 有关示例,请参阅 在渐变中使用系统颜色。
示例:
以下示例使用动态系统画笔引用来设置按钮的背景。
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowTitle="SystemColors Example" Background="White">
<StackPanel Margin="20">
<!-- Uses a dynamic resource to set the
background of a button.
If the desktop brush changes while this application
is running, this button will be updated. -->
<Button
Background="{DynamicResource {x:Static SystemColors.DesktopBrushKey}}"
Content="Hello, World!" />
</StackPanel>
</Page>
下一个示例使用静态系统画笔引用来设置按钮的背景。
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowTitle="SystemColors Example" Background="White">
<StackPanel Margin="20">
<!-- Uses a static brush to set the
background of a button.
If the desktop brush changes while this application
is running, this button will not be updated until
the page is loaded again. -->
<Button
Background="{x:Static SystemColors.DesktopBrush}"
Content="Hello, World!" />
</StackPanel>
</Page>
有关如何在渐变中使用系统颜色的示例,请参阅 在渐变中使用系统颜色。