我想我遗漏了一些东西。
无论如何,我想做一个metro风格的wpf主题,所以我从这个开始:
<Color x:Key="PrimaryColor">#8CBF26</Color>
<Color x:Key="TextColor">White</Color>
<Color x:Key="BackgroundColor">Black</Color>
<SolidColorBrush x:Key="PrimaryBrush" Color="{StaticResource ResourceKey=PrimaryColor}" />
<SolidColorBrush x:Key="ForgroundBrush" Color="{StaticResource ResourceKey=TextColor}" />
<SolidColorBrush x:Key="BackgroundBrush" Color="{StaticResource ResourceKey=BackgroundColor}" />
<FontFamily x:Key="FontFamily">Segoe WP, Segoe UI, Lucida Sans Unicode, Verdana</FontFamily>
<Style TargetType="{x:Type Window}">
<Setter Property="Background" Value="{StaticResource BackgroundBrush}" />
</Style>
<Style TargetType="{x:Type Run}">
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="FontFamily" Value="{StaticResource FontFamily}" />
<Setter Property="Foreground" Value="{StaticResource ForgroundBrush}" />
</Style>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="FontFamily" Value="{StaticResource FontFamily}" />
<Setter Property="Foreground" Value="{StaticResource ForgroundBrush}" />
</Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="{StaticResource BackgroundBrush}"/>
<Setter Property="BorderBrush" Value="{StaticResource ForgroundBrush}"/>
<Setter Property="BorderThickness" Value="2"/>
<Setter Property="Foreground" Value="{StaticResource ForgroundBrush}"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border x:Name="border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" >
<ContentPresenter Margin="{TemplateBinding Padding}" RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="true">
<Setter Property="Background" Value="{StaticResource ForgroundBrush}" />
<Setter Property="Foreground" Value="{StaticResource BackgroundBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
好吧,这工作得很好,但触发器的前景属性从未修改,我的猜测是,样式的TextBlock已经,所以它不能覆盖它的前景是否有任何解决这个问题的方法??
谢谢
Edit: TextBlock
样式应用于Button
的ControlTemplate
内部,以某种方式覆盖其自己的样式。我不知道该怎么办。
对我有用,你在Button
实例上设置了Foreground
吗?如果是这样的话,将根据优先级重写触发器。