2016-12-08 182 views
-1

当我将鼠标悬停在按钮上时,背景会更改为默认的浅蓝色背景,为什么我的触发器不会触发?我的按钮触发不会工作

<Style TargetType="Button" x:Key="btnBase"> 
    <Setter Property="OverridesDefaultStyle" Value="True"/> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type Button}"> 
       <Button Name="Button" 
         FontFamily="/Resources/Fonts/Source Sans Pro/#Source Sans Pro" 
         FontWeight="Bold" 
         FontSize="15" 
         BorderThickness="2" 
         Padding="14,3,14,3" 
         Foreground="{DynamicResource btnBaseForegroundColor}" 
         BorderBrush="{DynamicResource btnBaseBorderBrushColor}" 
         Background="{DynamicResource btnBaseBackgroundColor}"> 
        <ContentPresenter/> 
       </Button> 
       <ControlTemplate.Triggers> 
        <Trigger Property="IsMouseOver" Value="True"> 
         <Setter Property="Background" Value="Black"></Setter> 
        </Trigger> 
       </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 
+0

您必须更深入地使用按钮模板并添加额外的图层,您没有看到开始?但严重的是,尝试删除x:Key定义或将Style =“{DynamicResource btnBase}”添加到您制作按钮的xaml中。你也应该在样式中使用TemplateBinding作为背景,并用Setter设置默认值。 –

+0

看看这个答案是否可以帮助:http://stackoverflow.com/questions/17259280/how-do-you-change-background-for-a-button-mouseover-in-wpf –

+0

我看了看,但没有帮助。当我尝试你的链接示例时,我的按钮更改大小 –

回答

0

Background属性不用于为(标准)按钮的颜色着色。

所以触发器工作,但它没有你所期待的效果。

+0

有任何示例? –

+0

@ A.Game - 请参阅:http://stackoverflow.com/questions/17259280/how-do-you-change-background-for-a-button-mouseover-in-wpf?noredirect=1&lq=1 –

+0

谢谢,现在工作。与示例类似吗? –