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

标签 c# wpf animation

我已将以下 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.

最佳答案

您可以添加一个 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);

关于c# - 在 WPF 中的动画重复之间暂停,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23586041/

相关文章:

android - 如何停止在 android 中随机位置/角度旋转瓶子?

c# - 如何在GridView的TemplateField中找到Control?

c# - 您可以命名 Func<T> 类型的参数吗?

c# - 在 C# 中使用 GeoJSON.Net 为 Google map 打分

c# - WPF:通过 DataTrigger 设置 ListView View

javascript - 如何使网站的背景闪烁?

c# - 使用语句后,Sqlite 数据库保持打开状态并且文件锁定

c# - 为什么 XAML 中的 TextBlock.Foreground 属性不接受颜色?

c# - 如果内容不为空,未使用的 ListBoxItem 会导致绑定(bind)错误

ios - 自定义进度条自动布局的动画宽度约束