看着在WPF的各种开源的主题,我有点惊讶地看到,颜色不映射到系统颜色。 所以,如果你改变你的整个系统的配置,这些主题不会改变,以适应。
是否有正确使用系统的颜色,如果是这样,我怎么写一个按钮的风格,将利用这些颜色的任何主题?
举个例子,这里有一个按钮的风格:
<Style x:Key="specialButton" TargetType="Button">
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
<Setter Property="Background" Value="{StaticResource NormalBrush}"/>
<Setter Property="Margin" Value="2"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="border"
BorderThickness="1"
Background="{TemplateBinding Background}"
BorderBrush="{StaticResource NormalBorderBrush}"
Padding="1,1">
<ContentPresenter Name="content" HorizontalAlignment="Center" VerticalAlignment="Center" RecognizesAccessKey="True"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="border" Property="BorderBrush" Value="{StaticResource DarkBrush}"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="border" Property="Background" Value="{StaticResource PressedBrush}"/>
<Setter TargetName="border" Property="BorderBrush" Value="{StaticResource PressedBorderBrush}"/>
</Trigger>
<Trigger Property="IsDefaulted" Value="True">
<Setter TargetName="border" Property="BorderBrush" Value="{StaticResource DefaultedBorderBrush}"/>
</Trigger>
<Trigger Property="IsFocused" Value="True">
<Setter TargetName="border" Property="BorderBrush" Value="{StaticResource DefaultedBorderBrush}"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="border" Property="Background" Value="{StaticResource DisabledBackgroundBrush}"/>
<Setter TargetName="border" Property="BorderBrush" Value="{StaticResource DisabledBorderBrush}"/>
<Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
现在的问题是,让他们挂接到系统颜色如何指定命名的静态资源? 例如,背景可能是这样的:
<LinearGradientBrush x:Key="NormalBrush" StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="{DynamicResource {x:Static SystemColors.ControlLightLightColorKey}}" Offset="0.0"/>
<GradientStop Color="{DynamicResource {x:Static SystemColors.ControlLightColorKey}}" Offset="1.0"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
然而,这看上去一点也不像一个标准的按钮。 如果我使用XAMLPAD检查按钮,我可以看到以下内容:
<LinearGradientBrush x:Key="NormalBrush" StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FFF3F3F3" Offset="0.0"/>
<GradientStop Color="#FFEBEBEB" Offset="0.5"/>
<GradientStop Color="#FFDDDDDD" Offset="0.5"/>
<GradientStop Color="#FFCDCDCD" Offset="1.0"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
使用的颜色似乎是常量,而不是基于系统颜色。