Wpf 触发器不能正常工作?

Wpf 触发器不能正常工作?,wpf,xaml,triggers,styles,Wpf,Xaml,Triggers,Styles,嗯,我想我错过了一些东西 不管怎样,我试图制作一个metro风格的wpf主题,所以我从以下内容开始: <Color x:Key="PrimaryColor">#8CBF26</Color> <Color x:Key="TextColor">White</Color> <Color x:Key="BackgroundColor">Black</Color> <SolidColorBrush x:Key="Primary

嗯,我想我错过了一些东西

不管怎样,我试图制作一个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>
#8CBF26
白色
黑色
Segoe WP、Segoe UI、Lucida Sans Unicode、Verdana
好吧,这对所有人都很好,但触发器前景属性从未被修改过,我猜是文本块已经设置了样式,所以它不能覆盖它的前景色。这个问题有解决办法吗

谢谢

编辑:
文本块
样式应用于
按钮的
控制模板
中,以某种方式覆盖了它自己的样式。不知道该怎么办



对我有效,您是否在
按钮
实例上设置了
前景
?如果是这样,则会覆盖触发器,因为。

在按钮的样式中,我定义了前景和背景。。。当我点击按钮时,应用了样式,但前景颜色没有改变…@Petoj:好吧,正如我所说的,对我来说是这样的。我只是将所有这些复制到一些资源中,创建了一个按钮,按下后背景变成白色,前景变成黑色。我完全困惑了,我想我会尝试创建一个虚拟项目,然后在那里尝试!好的,现在它在那里工作了,我只是想弄清楚为什么它在我的主项目中不工作…@Petoj:你在“普通”资源中尝试过它吗,因为如果你把它放在
应用程序中。资源
文本块的样式将干扰按钮样式。你真的需要它吗?