[英]Can we create single Storyboard for Multiple buttons in WPF XAML?
<Window.Resources>
<Storyboard x:Key="ButtonEffect_01" AutoReverse="True" RepeatBehavior="Forever">
<ColorAnimationUsingKeyFrames
Storyboard.TargetProperty="(UIElement.Effect).(DropShadowEffect.Color)"
Storyboard.TargetName="btnAdd">
<EasingColorKeyFrame KeyTime="0" Value="Black"/>
<EasingColorKeyFrame KeyTime="0:0:0.4" Value="#FFF3FF00"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Button x:Name="btnAdd" Content="Add" Width="69" Height="27">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseEnter">
<ei:ControlStoryboardAction Storyboard="{StaticResource ButtonEffect_01}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
我还有3个其他按钮btnDelete,btnUpdate,btnBack我可以对所有这些按钮使用相同的Storyboard吗? 任何绑定方法?
您可以将动画共享到多个对象,但是需要检查动画状态。 为了防止错误,您可以在分配新目标之前停止动画:
private void MouseEnter(object sender, PointerRoutedEventArgs e)
{
ButtonEffect_01.Stop();
ButtonEffect_01.SetValue(Storyboard.TargetNameProperty, (sender as Button).Name);
ButtonEffect_01.Begin();
}
来源: http : //msdn.microsoft.com/en-us/library/windows/apps/dn376886.aspx
为了避免指定目标,您可以在Button
的Style
中定义故事板:
<Window.Resources>
<Style TargetType="Button">
<Style.Triggers>
<EventTrigger RoutedEvent="MouseEnter">
<BeginStoryboard>
<Storyboard AutoReverse="True" RepeatBehavior="Forever">
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Effect).(DropShadowEffect.Color)">
<EasingColorKeyFrame KeyTime="0" Value="Black"/>
<EasingColorKeyFrame KeyTime="0:0:0.4" Value="#FFF3FF00"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.