【发布时间】:2017-05-03 05:53:28
【问题描述】:
这是我的风格:
<UserControl.Resources>
<Style TargetType="Button" x:Key="Style2" BasedOn="{StaticResource MetroCircleButtonStyle}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="#000000"/>
<Setter Property="Background" Value="#ededed"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Foreground" Value="#ffffff"/>
<Setter Property="Background" Value="#009688"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="#FF808080"/>
</Trigger>
</Style.Triggers>
</Style>
</UserControl.Resources>
我是这样使用它的:
<Button x:Name="button" Content="abcdefg" Style="{DynamicResource Style2}" Width="45" Height="45" VerticalAlignment="Top" BorderThickness="0" FontSize="18" FontFamily="/WpfApplication2;component/Resources/#Vazir"/>
这完全可以。问题是当我尝试通过更改 XAML 或动态更改背景来更改按钮的背景时。当我这样做时,鼠标悬停效果不再起作用。
<Button x:Name="button" Content="abcdefg" Background="White" Style="{DynamicResource Style2}" Width="45" Height="45" VerticalAlignment="Top" BorderThickness="0" FontSize="18" FontFamily="/WpfApplication2;component/Resources/#Vazir"/>
或者
button.Background = Brushes.Transparent;
设置背景时,鼠标悬停效果不起作用,但我需要设置背景。怎么了?
【问题讨论】: