我已将以下FadeIn/FadeOut
动画应用于Canvas
中的WPF
。
var fadingInOutAnimation = new DoubleAnimation
{
From = 1,
To = 0,
Duration = new Duration(TimeSpan.FromMilliseconds(1000)),
AutoReverse = true,
RepeatBehavior = RepeatBehavior.Forever,
};
MyCanvas.BeginAnimation(OpacityProperty, fadingInOutAnimation);
现在我希望它在到达动画结束时暂停1秒钟,然后再重复。
所以就是这样:
Animation --- Pause (1 Sec) --- Animation --- Pause (1 Sec) and so on.
答案 0 :(得分:6)
您可以添加一个自动翻转和重复的故事板,但其持续时间比动画更长:
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);