WPF动画重复行为:永远不起作用 [英] WPF Animation Repeating Behavior: Forever doesn't work

查看:77
本文介绍了WPF动画重复行为:永远不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在尝试做一个关于椭圆的简单动画,其中的可见性属性在

I'm trying to do an simple animation about an ellipse where the visibility property at

1s =可见

2s =隐藏

此行为必须永远重复,直到某个事件将被启动。

this behavior has to be repeat forever untill an event wil be launched.

我试图这样做:

在此之后为
http://msdn.microsoft.com/en-us/library/cc294704.aspx

following this
http://msdn.microsoft.com/en-us/library/cc294704.aspx

但是当我进行PLAY测试动画时,动画会在时间轴的1s处停止。为什么?

but when I do PLAY to test animation, the animation stops at 1s of the timeline. Why?

相反,我期望从0到1秒的循环执行设置的可见性属性。

Instead I expect a loop from 0 to 1 seconds executing visibility properties setted.

任何人都知道为什么?

先谢谢

推荐答案

Hello
ludowanderlust。

无法动画可见性。 它可以是Visible,Collapsed或Hidden。 没有逐渐动画从一个到另一个。

Visibility cannot be animated.  It is either Visible, Collapsed or Hidden.  There is no gradual animation going from one to the other.

如果你想让你的UIElement淡出然后将不透明度从100%设置为0%,那么在下一个关键帧中你可以改变从可见到折叠的可见性。 如果您想循环动画,请确保您的第一个关键帧记录
可见性。

If you are wanting your UIElement to fade out then animate opacity from 100% to 0% then in the next keyframe you can change the visibility from visible to collapsed.  If you are wanting to loop the animation, then make sure your first keyframe records the visibility to visible.

所以类似这...

<Storyboard x:Key="Storyboard1" RepeatBehavior="Forever">
			<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="ellipse">
				<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
				<DiscreteObjectKeyFrame KeyTime="0:0:1" Value="{x:Static Visibility.Visible}"/>
				<DiscreteObjectKeyFrame KeyTime="0:0:1.1" Value="{x:Static Visibility.Collapsed}"/>
				<DiscreteObjectKeyFrame KeyTime="0:0:2" Value="{x:Static Visibility.Collapsed}"/>
			</ObjectAnimationUsingKeyFrames>
			<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="ellipse">
				<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
				<EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
				<EasingDoubleKeyFrame KeyTime="0:0:1.1" Value="0"/>
				<EasingDoubleKeyFrame KeyTime="0:0:2" Value="0"/>
			</DoubleAnimationUsingKeyFrames>
		</Storyboard>

在你的图片中,看起来你的Visiblity线上有一个超过10秒的关键帧,但它没有反映出来在您的代码中。 如果您不想让它在那里,请选择它并点击删除。

In you image, it looks like you have a keyframe on the Visiblity line that is past 10 seconds, but it is not reflected in your code.  Just select it and hit delete if you didn't mean for it to be there.

~Christine

~Christine

"但是当我播放以测试动画,动画在时间轴的1秒处停止。为什么?

您必须运行项目才能看到循环。 无论RepeatBehavior设置如何,Blend UI都只会在画板上显示一次动画。

You will have to run the project to see the loop.  The Blend UI will only show the animation once on the artboard regardless of the RepeatBehavior settings.


这篇关于WPF动画重复行为:永远不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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