private static AnimationClock Animate( DependencyObject animatable, DependencyProperty prop, AnimationTimeline anim, int duration, double?accel, double?decel, EventHandler func) { anim.AccelerationRatio = accel.GetValueOrDefault(0.0); anim.DecelerationRatio = decel.GetValueOrDefault(0.0); anim.Duration = (Duration)TimeSpan.FromMilliseconds((double)duration); anim.Freeze(); AnimationClock animClock = anim.CreateClock(); animClock.Completed += new EventHandler(animClock_Completed); if (func != null) { animClock.Completed += func; } animClock.Controller.Begin(); Animator.ClearAnimation(animatable, prop); ((IAnimatable)animatable).ApplyAnimationClock(prop, animClock); return(animClock); void animClock_Completed(object sender, EventArgs e) { Animator.ClearAnimation(animatable, prop); // ISSUE: method pointer animClock.Completed -= new EventHandler((object)this, __methodptr(\u003CAnimate\u003Eg__animClock_Completed\u007C0)); } }
private static AnimationClock AnimateElementDelayHelper(DependencyObject element, DependencyProperty property, AnimationTimeline anim, double delaySeconds) { if (!(element is IAnimatable)) { throw new InvalidOperationException("Element must be IAnimatable."); } anim.FillBehavior = FillBehavior.HoldEnd; anim.Completed += new EventHandler(anim_Completed); anim.AccelerationRatio = .15; anim.DecelerationRatio = .85; //object value = element.GetValue(property); //animatable.BeginAnimation(property, null); //element.SetValue(property, value); AnimationClock clock = anim.CreateClock(); DependencyCombo dc = new DependencyCombo(element, property); DispatcherTimer delayTimer = new DispatcherTimer(); delayTimer.Interval = TimeSpan.FromSeconds(delaySeconds); delayTimer.Tick += new EventHandler(delayTimer_Tick); delayTimer.Start(); SavedAnimations.Add(delayTimer, new AnimationData(clock, dc)); return(clock); }
private static AnimationClock Animate( DependencyObject animatable, DependencyProperty prop, AnimationTimeline anim, int duration, double?acceleration, double?deceleration, EventHandler func ) { if (acceleration.HasValue) { anim.AccelerationRatio = acceleration.GetValueOrDefault(0); } if (deceleration.HasValue) { anim.DecelerationRatio = deceleration.GetValueOrDefault(0); } anim.Duration = TimeSpan.FromMilliseconds(duration); anim.Freeze(); AnimationClock animClock = anim.CreateClock(); // When animation is complete, remove animation and set the animation's "To" // value as the new value of the property. EventHandler eh = null; eh = delegate(object sender, EventArgs e) { animatable.SetValue(prop, animatable.GetValue(prop)); ((IAnimatable)animatable).ApplyAnimationClock(prop, null); animClock.Completed -= eh; }; animClock.Completed += eh; // assign completed eventHandler, if defined if (func != null) { animClock.Completed += func; } animClock.Controller.Begin(); // goferit ((IAnimatable)animatable).ApplyAnimationClock(prop, animClock); return(animClock); }
private void ColorAnimationBasicTest(AnimationTimeline animation, Color defaultOriginValue, Color defaultDestinationValue, Color expectedStartValue, Color expectedMiddleValue, Color expectedEndValue) { AnimationTimelineClock clock = (AnimationTimelineClock)animation.CreateClock(); TestRootClock rootClock = new TestRootClock(); clock.Begin(rootClock); rootClock.Tick(TimeSpan.Zero); Assert.AreEqual(expectedStartValue, (Color)animation.GetCurrentValue(defaultOriginValue, defaultDestinationValue, clock)); rootClock.Tick(animation.Duration.TimeSpan.Scale(0.5)); Assert.AreEqual(expectedMiddleValue, (Color)animation.GetCurrentValue(defaultOriginValue, defaultDestinationValue, clock)); rootClock.Tick(animation.Duration.TimeSpan); Assert.AreEqual(expectedEndValue, (Color)animation.GetCurrentValue(defaultOriginValue, defaultDestinationValue, clock)); }
/// <summary> /// This summary has not been prepared yet. NOSUMMARY - pantal07 /// </summary> protected void PrepareAnimation(string className, string propertyName, string from, string to, string defaultValue) { animatingObject = GetAnimatingObject(propertyName, className); property = GetAnimatingProperty(propertyName); if (property.PropertyType.IsValueType) { this.from = MakeValue(from, property.PropertyType); this.to = MakeValue(to, property.PropertyType); this.defaultValue = MakeValue(defaultValue, property.PropertyType); } else { this.from = MakeObject(from); this.to = MakeObject(to); this.defaultValue = MakeObject(defaultValue); } // The FactoryParser already set this value. Clear it! ((DependencyObject)animatingObject).ClearValue(property); AnimationTimeline animation = MakeAnimation(variation, property.PropertyType); animationClock = animation.CreateClock(); switch (testType) { case TestType.AnimationFirst: case TestType.AnimationFirstAndClearFifo: case TestType.AnimationFirstAndClearLifo: animatingObject.ApplyAnimationClock(property, animationClock); ((DependencyObject)animatingObject).SetValue(property, this.defaultValue); break; case TestType.BaseValueFirst: case TestType.BaseValueFirstAndClearFifo: case TestType.BaseValueFirstAndClearLifo: ((DependencyObject)animatingObject).SetValue(property, this.defaultValue); animatingObject.ApplyAnimationClock(property, animationClock); break; case TestType.NoBaseValue: case TestType.NoBaseValueAndClearValue: animatingObject.ApplyAnimationClock(property, animationClock); break; } }
private static AnimationClock AnimateElementHelper(DependencyObject element, DependencyProperty property, AnimationTimeline anim) { if (!(element is IAnimatable)) { throw new InvalidOperationException("Element must be IAnimatable."); } anim.FillBehavior = FillBehavior.HoldEnd; anim.Completed += new EventHandler(anim_Completed); anim.AccelerationRatio = .15; anim.DecelerationRatio = .85; AnimationClock clock = anim.CreateClock(); DependencyCombo dc = new DependencyCombo(element, property); IAnimatable animatable = (IAnimatable)dc.DObject; animatable.ApplyAnimationClock(dc.DProperty, null); animatable.ApplyAnimationClock(dc.DProperty, clock); if (RunningAnimation.Values.Contains(dc)) { List <AnimationClock> toDelete = new List <AnimationClock>(); foreach (KeyValuePair <AnimationClock, DependencyCombo> kvp in RunningAnimation) { if (kvp.Value.Equals(dc)) { toDelete.Add(kvp.Key); kvp.Key.Controller.Stop(); } } foreach (AnimationClock key in toDelete) { RunningAnimation.Remove(key); } } RunningAnimation.Add(clock, dc); return(clock); }