當我將鼠標懸停在按鈕上時,背景會更改爲默認的淺藍色背景,爲什麼我的觸發器不會觸發?我的按鈕觸發不會工作
<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>
您必須更深入地使用按鈕模板並添加額外的圖層,您沒有看到開始?但嚴重的是,嘗試刪除x:Key定義或將Style =「{DynamicResource btnBase}」添加到您製作按鈕的xaml中。你也應該在樣式中使用TemplateBinding作爲背景,並用Setter設置默認值。 –
看看這個答案是否可以幫助:http://stackoverflow.com/questions/17259280/how-do-you-change-background-for-a-button-mouseover-in-wpf –
我看了看,但沒有幫助。當我嘗試你的鏈接示例時,我的按鈕更改大小 –