XAML C#WPF制作有序动画序列的最佳有效方法 [英] XAML C# WPF Best efficient way to do an ordered sequence of animations

查看:35
本文介绍了XAML C#WPF制作有序动画序列的最佳有效方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在标签上进行一系列动画处理,例如,首先执行从0到1的不透明度动画,反之亦然,并且只在不透明度动画的末尾而不是在前景动画之前.我想在XAML代码中执行此操作,然后从C#代码开始和结束动画.哪种方法最有效?

I would like to do a sequence of animations on a label, for example, first do opacity animations from values 0 to 1 and vice versa and just at the end of opacity animation and not before a foreground animation. I would like to do it in XAML code and then start and finish de animation from C# code. Which is the best and efficient way to do it?

欢迎所有回复!

谢谢.

推荐答案

最简单的方法是使用合适的 BeginTime Duration 属性在单个故事板上定义整个动画.这样,整个动画可以作为一个单元启动和停止,但是可以有不同的序列.

The easiest way is to define the entire animation in a single storyboard with suitable BeginTime and Duration properties. This way the entire animation can be started and stopped as a unit, but you can have different sequences.

例如:

<Storyboard Duration="0:00:06">
    <DoubleAnimation Duration="0:0:4" Storyboard.TargetName="gear1RotateTransform" Storyboard.TargetProperty="Angle" From="-600" To="0"/>
    <DoubleAnimation Duration="0:0:4" Storyboard.TargetName="gear2RotateTransform" Storyboard.TargetProperty="Angle" From="600" To="0"/>
    <DoubleAnimation Duration="0:0:4" Storyboard.TargetName="gear3RotateTransform" Storyboard.TargetProperty="Angle" From="-600" To="0"/>
    <DoubleAnimation BeginTime="0:0:1" Duration="0:00:02" Storyboard.TargetName="firstLetter" Storyboard.TargetProperty="Opacity" From="0.0" To="1.0"/>
    <DoubleAnimation BeginTime="0:0:2" Duration="0:00:02" Storyboard.TargetName="secondLetter" Storyboard.TargetProperty="Opacity" From="0.0" To="1.0"/>
    <DoubleAnimation BeginTime="0:0:3" Duration="0:00:02" Storyboard.TargetName="thirdLetter" Storyboard.TargetProperty="Opacity" From="0.0" To="1.0"/>
    <DoubleAnimation BeginTime="0:0:4" Duration="0:00:02" Storyboard.TargetName="siteLink" Storyboard.TargetProperty="Opacity" From="0.0" To="1.0"/>
    <DoubleAnimation BeginTime="0:0:4" Duration="0:00:02" Storyboard.TargetName="siteLinkTop" Storyboard.TargetProperty="Opacity" From="0.0" To="1.0"/>
</Storyboard>

此故事板在最初的4秒钟内更改了3个旋转变换的值,但 firstLetter 项上的不透明度直到一秒钟过去之后才开始改变,并且仅在2秒 siteLink siteLinkTop 元素的不透明度直到4秒(齿轮旋转动画完成)之后才发生变化.

This storyboard changes the values on the 3 rotate transforms for the first 4 seconds, but the opacity on the firstLetter item doesn't start to change until after one second has passed and it only runs for 2 seconds. The siteLink and siteLinkTop elements don't have their opacity changed until after 4 seconds (and the gear rotation animation has finished).

这篇关于XAML C#WPF制作有序动画序列的最佳有效方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆