我的按钮Style
中定义的以下通用ControlTemplate.Resources
有什么问题?
<ControlTemplate x:Key="ZeroButtonTemplate" TargetType="Button">
<ControlTemplate.Resources>
<Style TargetType="{x:Type Rectangle}">
<Style.Triggers>
<DataTrigger Binding="{Binding IsRunning}" Value="True">
<Setter Property="Fill" Value="LightGray" />
</DataTrigger>
<EventTrigger RoutedEvent="Button.MouseEnter">
<BeginStoryboard>
<Storyboard>
<ColorAnimation From="Black" To="Red" Duration="00:00:00.5" Storyboard.TargetProperty="Fill" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>
</Style>
</ControlTemplate.Resources>
<ContentPresenter Content="{TemplateBinding Content}" />
</ControlTemplate>
DataTrigger
和EventTrigger
似乎都没有效果。
为了完成,我的Button定义如下:
<Button Template="{StaticResource ZeroButtonTemplate}">
<Button.Content>
<Rectangle Width="15" Height="15" Fill="Black" />
</Button.Content>
</Button>
答案 0 :(得分:1)
将动画的目标属性更改为Fill.Color
<ColorAnimation From="Black" To="Red" Duration="00:00:00.5" Storyboard.TargetProperty="Fill.Color" />