我想让我的按钮(我ControlTemplate
为 a定义 a Button
)在鼠标向上(单击按钮并离开鼠标按钮)时触发我的动画。那是因为Button
没有VisualState
喜欢MouseUp
,但只有Pressed
在点击时。
我希望在不按住按钮的情况下执行动画,我只想单击并释放。
这是我的代码(你可以看到我放了但它没有产生任何影响:
<Window.Resources>
<Style x:Key="ButtonStyle1" TargetType="Button">
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border x:Name="BorderOfTemplate" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" RenderTransformOrigin=".5,.5">
<Border.Triggers>
<EventTrigger RoutedEvent="Click">
<BeginStoryboard>
<Storyboard>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="AnimatedScaleTransform" Storyboard.TargetProperty="ScaleX" Duration="0:0:3" RepeatBehavior="1x">
<LinearDoubleKeyFrame KeyTime="0:0:3" Value=".1" />
<SplineDoubleKeyFrame Value="1" KeyTime="0:0:3" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="AnimatedScaleTransform" Storyboard.TargetProperty="ScaleY" Duration="0:0:3" RepeatBehavior="1x">
<LinearDoubleKeyFrame KeyTime="0:0:3" Value=".1" />
<SplineDoubleKeyFrame Value="1" KeyTime="0:0:3" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="AnimatedTranslateTransform" Storyboard.TargetProperty="Y" Duration="0:0:3" RepeatBehavior="1x">
<LinearDoubleKeyFrame Value="-170" KeyTime="0:0:2" />
<SplineDoubleKeyFrame Value="1" KeyTime="0:0:3" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Border.Triggers>
<Border.RenderTransform>
<TransformGroup>
<RotateTransform x:Name="AnimatedRotateTransform" />
<ScaleTransform x:Name="AnimatedScaleTransform" />
<TranslateTransform x:Name="AnimatedTranslateTransform" />
</TransformGroup>
</Border.RenderTransform>
<here some VisualStateManager>
</here some VisualStateManager>
enter code here
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
谢谢!