public void AnimationExpressionFillBehaviorStopTest() { DoubleAnimation animation = new DoubleAnimation { From = 10, To = 20, FillBehavior = FillBehavior.Stop }; TestRootClock rootClock = new TestRootClock(); rootClock.Tick(TimeSpan.FromSeconds(1)); FrameworkElement element = new FrameworkElement(); Assert.AreEqual(Double.NaN, element.Width); AnimationTimelineClock animationClock = (AnimationTimelineClock)animation.CreateClock(); element.ApplyAnimationClock(FrameworkElement.WidthProperty, animationClock); animationClock.Begin(rootClock); rootClock.Tick(TimeSpan.FromSeconds(1)); Assert.AreEqual(10, element.Width); rootClock.Tick(TimeSpan.FromSeconds(2)); Assert.AreEqual(Double.NaN, element.Width); }
private void ApplyAnimationClockTest(DoubleAnimation animation) { FrameworkElement element = new FrameworkElement(); TestRootClock rootClock = new TestRootClock(); rootClock.Tick(TimeSpan.FromSeconds(0)); AnimationTimelineClock clock = (AnimationTimelineClock)animation.CreateClock(); clock.Begin(rootClock); element.Width = 10; Assert.AreEqual(10, element.Width); element.ApplyAnimationClock(FrameworkElement.WidthProperty, clock); Assert.AreEqual(10, element.Width); rootClock.Tick(TimeSpan.FromSeconds(0.5)); Assert.AreEqual(15, element.Width); rootClock.Tick(TimeSpan.FromSeconds(1)); Assert.AreEqual(20, element.Width); clock.Stop(); element.Width = 30; Assert.AreEqual(30, element.Width); }
private void SetGlowAnimation() { if (Indicator == null || glow == null || Indicator.ActualWidth.IsClose(currentAnimatedIndicatorWidth)) { return; } currentAnimatedIndicatorWidth = Indicator.ActualWidth; double currentOffset = glow.Margin.Left; if (currentAnimationClock != null) { ((IAnimatable)glow).RootClock.RemoveClock(currentAnimationClock); currentAnimationClock = null; } if (Indicator.ActualWidth > 0) { double startOffset = -glow.ActualWidth; double endOffset = Indicator.ActualWidth; TimeSpan time = TimeSpan.FromSeconds((endOffset - startOffset) / 200); ThicknessAnimationUsingKeyFrames thicknessAnimation = new ThicknessAnimationUsingKeyFrames(); thicknessAnimation.KeyFrames.Add(new LinearThicknessKeyFrame { Value = new Thickness(startOffset, 0, 0, 0), KeyTime = KeyTime.FromTimeSpan(TimeSpan.Zero) }); thicknessAnimation.KeyFrames.Add(new LinearThicknessKeyFrame { Value = new Thickness(endOffset, 0, 0, 0), KeyTime = KeyTime.FromTimeSpan(time) }); thicknessAnimation.Duration = new Duration(time + TimeSpan.FromSeconds(1)); thicknessAnimation.RepeatBehavior = RepeatBehavior.Forever; thicknessAnimation.BeginTime = -time.Scale((currentOffset - startOffset) / (endOffset - startOffset)); currentAnimationClock = (AnimationTimelineClock)thicknessAnimation.CreateClock(); glow.ApplyAnimationClock(FrameworkElement.MarginProperty, currentAnimationClock); currentAnimationClock.Begin(((IAnimatable)glow).RootClock); } else { glow.ClearAnimationClocks(FrameworkElement.MarginProperty); } }
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)); }
public void ColorAnimationKeyFrameRepeatTest() { ColorAnimationUsingKeyFrames animation; animation = new ColorAnimationUsingKeyFrames(); animation.KeyFrames.Add(new LinearColorKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)), Value = Color.FromUInt32(0) }); animation.KeyFrames.Add(new LinearColorKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1)), Value = Color.FromUInt32(100) }); animation.Duration = new Duration(TimeSpan.FromSeconds(2)); animation.RepeatBehavior = RepeatBehavior.Forever; TestRootClock rootClock = new TestRootClock(); AnimationTimelineClock clock = (AnimationTimelineClock)animation.CreateClock(); clock.Begin(rootClock); rootClock.Tick(TimeSpan.FromSeconds(0.1)); Assert.AreEqual(Color.FromUInt32(10), (Color)animation.GetCurrentValue(0.0, 0.0, clock)); rootClock.Tick(TimeSpan.FromSeconds(0.9)); Assert.AreEqual(Color.FromUInt32(90), (Color)animation.GetCurrentValue(0.0, 0.0, clock)); rootClock.Tick(TimeSpan.FromSeconds(1)); Assert.AreEqual(Color.FromUInt32(100), (Color)animation.GetCurrentValue(0.0, 0.0, clock)); rootClock.Tick(TimeSpan.FromSeconds(1.9)); Assert.AreEqual(Color.FromUInt32(100), (Color)animation.GetCurrentValue(0.0, 0.0, clock)); rootClock.Tick(TimeSpan.FromSeconds(2.1)); Assert.AreEqual(Color.FromUInt32(10), (Color)animation.GetCurrentValue(0.0, 0.0, clock)); rootClock.Tick(TimeSpan.FromSeconds(2.9)); Assert.AreEqual(Color.FromUInt32(90), (Color)animation.GetCurrentValue(0.0, 0.0, clock)); }
public void DoubleAnimationKeyFrameRepeatTest() { DoubleAnimationUsingKeyFrames animation; animation = new DoubleAnimationUsingKeyFrames(); animation.KeyFrames.Add(new LinearDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)), Value = 0 }); animation.KeyFrames.Add(new LinearDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1)), Value = 1 }); animation.Duration = new Duration(TimeSpan.FromSeconds(2)); animation.RepeatBehavior = RepeatBehavior.Forever; TestRootClock rootClock = new TestRootClock(); AnimationTimelineClock clock = (AnimationTimelineClock)animation.CreateClock(); clock.Begin(rootClock); rootClock.Tick(TimeSpan.FromSeconds(0.1)); Assert.AreEqual(0.1, (double)animation.GetCurrentValue(0.0, 0.0, clock)); rootClock.Tick(TimeSpan.FromSeconds(0.9)); Assert.AreEqual(0.9, (double)animation.GetCurrentValue(0.0, 0.0, clock)); rootClock.Tick(TimeSpan.FromSeconds(1)); Assert.AreEqual(1, (double)animation.GetCurrentValue(0.0, 0.0, clock)); rootClock.Tick(TimeSpan.FromSeconds(1.9)); Assert.AreEqual(1, (double)animation.GetCurrentValue(0.0, 0.0, clock)); rootClock.Tick(TimeSpan.FromSeconds(2.1)); Assert.AreEqual(0.1, (double)animation.GetCurrentValue(0.0, 0.0, clock)); rootClock.Tick(TimeSpan.FromSeconds(2.9)); Assert.AreEqual(0.9, (double)animation.GetCurrentValue(0.0, 0.0, clock)); }