在WPF中动画重复之间的暂停

3
我已经将以下的 FadeIn/FadeOut 动画应用到了在 WPF 中的一个 Canvas 里。
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.
2个回答

8

您可以添加一个Storyboard来实现自动反转和重复,但其持续时间比动画更长:

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);

1

尝试在动画中使用BeginTime来启动循环之间的暂停。

<Storyboard TargetProperty ="(Fill).(SolidColorBrush.Color)"
            BeginTime ="00:00:00"
            RepeatBehavior ="Forever"
            AutoReverse="True">
<ColorAnimation From="Red" To="Yellow" 
            BeginTime="00:00:02"
            Duration="00:00:01"/>
</Storyboard>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接