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

yiytaume  于 2023-03-24  发布在  其他
关注(0)|答案(2)|浏览(204)

我将下面的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.
bjp0bcyl

bjp0bcyl1#

您可以添加一个情节串联板来执行自动反转和重复,但它的持续时间比动画长:

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

h22fl7wq2#

尝试在动画中使用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>

相关问题