在WPF中动画之间的重复之间暂停 [英] Pause between repeats in an animation in WPF
本文介绍了在WPF中动画之间的重复之间暂停的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已将以下 FadeIn / FadeOut
动画应用到 WPF中的
。 Canvas
I have applied the following FadeIn/FadeOut
animation to a Canvas
in WPF
.
var fadingInOutAnimation = new DoubleAnimation
{
From = 1,
To = 0,
Duration = new Duration(TimeSpan.FromMilliseconds(1000)),
AutoReverse = true,
RepeatBehavior = RepeatBehavior.Forever,
};
MyCanvas.BeginAnimation(OpacityProperty, fadingInOutAnimation);
现在,我希望它在到达动画结尾时暂停一秒钟,然后再次重复。
Now I want it to pause for 1 second when it reaches the end of the animation before repeating again.
就像这样:
Animation --- Pause (1 Sec) --- Animation --- Pause (1 Sec) and so on.
推荐答案
您可能会添加一个自动反转的Storyboard。和重复,但持续时间比动画更长:
You might add a Storyboard that does the auto-reversing and repetition, but that has a longer duration than the animation:
var fadeInOutAnimation = new DoubleAnimation()
{
From = 1,
To = 0,
Duration = TimeSpan.FromSeconds(1),
};
var storyboard = new Storyboard
{
Duration = TimeSpan.FromSeconds(2),
AutoReverse = true,
RepeatBehavior = RepeatBehavior.Forever
};
Storyboard.SetTarget(fadeInOutAnimation, MyCanvas);
Storyboard.SetTargetProperty(fadeInOutAnimation,
new PropertyPath(Canvas.OpacityProperty));
storyboard.Children.Add(fadeInOutAnimation);
MyCanvas.BeginStoryboard(storyboard);
这篇关于在WPF中动画之间的重复之间暂停的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文