简体   繁体   English

如何在运行时更改“ AnimationClock-timeline”属性?

[英]How to change `AnimationClock-timeline` properties at run-time?

I used AnimationClock like this : 我像这样使用AnimationClock

   DoubleAnimation ScrollAnimation = new DoubleAnimation();
   ....
     AnimationClock AnimClock = new AnimationClock();
     AnimClock = ScrollAnimation.CreateClock();
     TranslateTransform oTransform = (TranslateTransform)transGroup.Children[1];
     oTransform.ApplyAnimationClock(prop, AnimClock);
     AnimClock.Controller.SpeedRatio = ScrollSlider.Value; 
     AnimClock.Completed += ScrollClockController_Completed;
     oTransform.BeginAnimation(TranslateTransform.XProperty, ScrollAnimation);

My code works fine, But when I try to change AnimationClock-timeline properties ( RepeatBehavior or AutoReverse or etc.) after BeginAnimation the following error occurs: 我的代码工作正常,但是当我尝试在BeginAnimation之后更改AnimationClock-timeline属性( RepeatBehaviorAutoReverse等)时,会发生以下错误:

AnimClock.Timeline.AutoReverse = true;

Cannot set a property on object 'System.Windows.Media.Animation.DoubleAnimation' because it is in a read-only state 无法在对象'System.Windows.Media.Animation.DoubleAnimation'上设置属性,因为它处于只读状态

"Although most Timeline properties are animatable and can be data bound, changing the property values of an active Timeline seems to have no effect. That's because, when a Timeline is begun, the timing system makes a copy of the Timeline and uses it to create a Clock object. Modifying the original has no effect on the system's copy. “尽管大多数时间轴属性都是可动画的,并且可以绑定数据,但是更改活动时间轴的属性值似乎没有任何作用。这是因为,当时间轴开始时,计时系统会复制时间轴并使用其创建一个Clock对象,修改原始对象不会影响系统的副本。

For a Timeline to reflect changes, its clock must be regenerated and used to replace the previously created clock. 为了使时间轴反映更改,必须重新生成其时钟并将其用于替换先前创建的时钟。 Clocks are not regenerated for you automatically. 时钟不会自动为您重新生成。 The following are several ways to apply timeline changes: 以下是应用时间轴更改的几种方法:

If the timeline is or belongs to a Storyboard, you can make it reflect changes by reapplying its storyboard using a BeginStoryboard or the Begin method. 如果时间轴是情节提要或属于情节提要,则可以通过使用BeginStoryboard或Begin方法重新应用其情节提要来使其反映更改。 This has the side effect of also restarting the animation. 这具有还会重新启动动画的副作用。 In code, you can use the Seek method to advance the storyboard back to its previous position. 在代码中,可以使用Seek方法将情节提要板返回到其先前位置。

If you applied an animation directly to a property using the BeginAnimation method, call the BeginAnimation method again and pass it the animation that has been modified. 如果使用BeginAnimation方法将动画直接应用于属性,请再次调用BeginAnimation方法并将经过修改的动画传递给它。

If you are working directly at the clock level, create and apply a new set of clocks and use them to replace the previous set of generated clocks." 如果您直接在时钟级别上工作,请创建并应用一组新的时钟,并使用它们来替换之前生成的一组时钟。”

I found the answer at this page 我在此页面找到了答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM