0
我的WPF應用程序未更新單擊按鈕時的按鈕背景,並且鼠標光標位於它上面。背景顏色仍然是淺綠色。其他屬性更改正常。哪裏不對?單擊按鈕時按鈕背景顏色未更新
文件ControlStyles.xaml
...
<Style TargetType="{x:Type Button}" x:Key="MyButton">
<Setter Property="Foreground" Value="Black"/>
<Setter Property="Background" Value="DarkCyan"/>
<Setter Property="Margin" Value="5"/>
<Setter Property="FontSize" Value="20"/>
<Style.Triggers>
<Trigger Property="Control.IsMouseOver" Value="true">
<Setter Property="Control.FontStyle" Value="Italic"></Setter>
<Setter Property="Control.Foreground" Value="Red"></Setter>
<Setter Property="Control.Background" Value="black"></Setter>
</Trigger>
<Trigger Property="Button.IsPressed" Value="true">
<Setter Property="Control.Foreground" Value="Firebrick"></Setter>
<Setter Property="Control.Background" Value="Yellow"></Setter>
</Trigger>
</Style.Triggers>
</Style>
...
Window.xaml
...
<Button Name="btn7" Content="7" Grid.Column="0" Grid.Row="3" Style="{StaticResource MyButton}" Click="btn7_Click"/>
<Button Name="btn8" Content="8" Grid.Column="1" Grid.Row="3" Style="{StaticResource MyButton}" Click="btn8_Click"/>
...
鼠標懸停:是不是在所有工作(背景顏色是不會改變)。按鈕點擊:以奇怪的方式工作:當鼠標光標離開按鈕時,它會改變顏色 –