我想制作我的按钮(我为ControlTemplate
定义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>
谢谢!
答案 0 :(得分:0)
根据this article,Silverlight的普通EventTrigger
仅支持Loaded
事件。
但是,使用EventTrigger
中的System.Windows.Interactivity
,您似乎可以使用其他活动,例如点击或 MouseLeftButtonUp 。请参阅此文章以获取示例:codeproject.com