我希望在点击按钮事件之前显示一些按钮动画。我正在使用以下XAML来实现这一点,但似乎Button.IsPressed
触发器在点击事件后被触发。
如何设置触发器以便在点击事件之前首先显示动画?
<Button x:Name="button"
Width="131"
Height="37"
Content="Button"
Margin="0,0,0,22"
Click="button_Click">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Style.Triggers>
<Trigger Property="Button.IsPressed" Value="True">
<Trigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Width"
From="130"
To="0"
Duration="0:0:2"/>
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
编辑:我尝试了同样的事情。
<EventTrigger RoutedEvent="PreviewMouseLeftButtonDown">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Width"
From="130"
To="0"
Duration="0:0:2"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>