如何:使用系统画笔绘制区域
SystemColors 类可访问系统画笔和颜色,例如 ControlBrush、ControlBrushKey 和 DesktopBrush。 系统画笔是使用指定系统颜色绘制区域的 SolidColorBrush 对象。 系统画笔总是生成纯色填充,它不能用于创建渐变。
可以将系统画笔用作静态资源,也可以用作动态资源。 如果希望在应用程序运行期间画笔自动进行更新(当用户更改系统画笔时),请使用动态资源;否则请使用静态资源。 SystemColors 类包含大量静态属性,这些属性严格遵循命名约定:
*<SystemColor>*Brush
获取对指定系统颜色的 SolidColorBrush 的静态引用。
*<SystemColor>*BrushKey
获取对指定系统颜色的 SolidColorBrush 的动态引用。
*<SystemColor>*Color
获取对指定系统颜色的 Color 结构的静态引用。
*<SystemColor>*ColorKey
获取对指定系统颜色的 Color 结构的动态引用。
系统颜色是可用于配置画笔的 Color 结构。 例如,可以通过使用系统颜色设置 LinearGradientBrush 对象的梯度停止点的 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>
有关演示如何在渐变中使用系统颜色的示例,请参阅在渐变中使用系统颜色。
另请参阅
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈