Практическое руководство. Использование системных цветов в градиенте
Обновлен: Ноябрь 2007
Чтобы использовать системный цвет в градиенте, используются статические свойства класса SystemColors*<SystemColor>*Color и *<SystemColor>*ColorKey для получения ссылки на цвет, где <SystemColor> является именем необходимого системного цвета. Используйте свойства *<SystemColor>*ColorKey, если необходимо создать динамическую ссылку, которая обновляется автоматически по мере изменения темы системы. В противном случае, используйте свойства *<SystemColor>*Color.
Пример
В следующем примере используются динамические ресурсы цвета системы для создания градиента.
<Page xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
WindowTitle="Dynamic System Colors Example" Background="White">
<StackPanel Margin="20">
<!-- Uses dynamic references to system colors to set
the colors of gradient stops.
If these system colors change while this application
is running, the gradient will be updated
automatically. -->
<Button Content="Hello, World!">
<Button.Background>
<LinearGradientBrush>
<LinearGradientBrush.GradientStops>
<GradientStop Offset="0.0"
Color="{DynamicResource {x:Static SystemColors.DesktopColorKey}}" />
<GradientStop Offset="1.0"
Color="{DynamicResource {x:Static SystemColors.ControlLightLightColorKey}}" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Button.Background>
</Button>
</StackPanel>
</Page>
В следующем примере используются статические ресурсы цвета системы для создания градиента.
<Page xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
WindowTitle="Static System Colors Example" Background="White">
<StackPanel Margin="20">
<!-- Uses static references to system colors to set
the colors of gradient stops.
If these system colors change while this application
is running, this button will not be updated until
the page is loaded again. -->
<Button Content="Hello, World!">
<Button.Background>
<LinearGradientBrush>
<LinearGradientBrush.GradientStops>
<GradientStop Offset="0.0"
Color="{x:Static SystemColors.DesktopColor}" />
<GradientStop Offset="1.0"
Color="{x:Static SystemColors.ControlLightLightColor}" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Button.Background>
</Button>
</StackPanel>
</Page>
Этот пример является частью большого примера; полный пример см. в разделе Пример использования системных кистей и цветов.
См. также
Задачи
Практическое руководство. Закраска области с помощью системной кисти
Основные понятия
Общие сведения о закраске сплошным цветом и градиентом