<Storyboard x:Key="ShadowAnimation">
<DoubleAnimationUsingKeyFrames
AutoReverse="True"
RepeatBehavior="Forever"
Storyboard.TargetName="ShadowEffect"
Storyboard.TargetProperty="Opacity"
Duration="0:0:1">
<DiscreteDoubleKeyFrame KeyTime="0:0:0" Value="0" />
<DiscreteDoubleKeyFrame KeyTime="0:0:0.5" Value="0.5" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames
AutoReverse="True"
RepeatBehavior="Forever"
Storyboard.TargetName="myBorder"
Storyboard.TargetProperty="Opacity"
Duration="0:0:1">
<DiscreteDoubleKeyFrame KeyTime="0:0:0" Value="0" />
<DiscreteDoubleKeyFrame KeyTime="0:0:0.5" Value="1" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
很多方法可以实现,这里介绍使用离散型关键帧动画实现。
怎么使用查看:WPF 控制动画开关-CSDN博客
属性解释:
AutoReverse="True" //自动翻转状态
RepeatBehavior="Forever" //持续时间 永久
Storyboard.TargetName="ShadowEffect" //要操作的界面元素名称
Storyboard.TargetProperty="Opacity" //要操作的界面元素的属性
Duration="0:0:1" //一个循环持续时间
关键帧:
<DiscreteDoubleKeyFrame KeyTime="0:0:0" Value="0" /> //动画开始时 Opacity=0
<DiscreteDoubleKeyFrame KeyTime="0:0:0.5" Value="0.5" /> //动画时间到0.5s时 Opacity=0.5
即:开始时 Opacity=0,过了0.5s后Opacity变为0.5,然后持续到1s,然后重新执行动画;不结束的话会一直执行。