示例#1
0
        public void StoryboardTargetTest()
        {
            XamlNamespaces namespaces = new XamlNamespaces("http://schemas.microsoft.com/winfx/2006/xaml/presentation");

            ColorAnimation colorAnimation = new ColorAnimation {
                From = Colors.Green, To = Colors.Blue
            };

            Storyboard.SetTargetProperty(colorAnimation, PropertyPath.Parse("(Control.Background).(SolidColorBrush.Color)", namespaces));

            Storyboard storyboard = new Storyboard();

            storyboard.Children.Add(colorAnimation);

            TestRootClock rootClock = new TestRootClock();

            Control control = new Control();

            control.SetAnimatableRootClock(new AnimatableRootClock(rootClock, true));
            control.Background = new SolidColorBrush(Colors.Red);

            storyboard.Begin(control);

            rootClock.Tick(TimeSpan.FromSeconds(0));
            Assert.AreEqual(Colors.Green, ((SolidColorBrush)control.Background).Color);

            rootClock.Tick(TimeSpan.FromSeconds(0.5));
            Assert.IsTrue(Color.FromArgb(255, 0, (byte)(Colors.Green.G / 2), (byte)(Colors.Blue.B / 2)).IsClose(((SolidColorBrush)control.Background).Color));

            rootClock.Tick(TimeSpan.FromSeconds(1));
            Assert.AreEqual(Colors.Blue, ((SolidColorBrush)control.Background).Color);
        }
示例#2
0
        public void SequentialTimelineClockStoryboardTest()
        {
            DoubleAnimation animation1 = new DoubleAnimation {
                To = 100, Duration = new Duration(TimeSpan.FromSeconds(1))
            };
            DoubleAnimation animation2 = new DoubleAnimation {
                To = 200, Duration = new Duration(TimeSpan.FromSeconds(0))
            };
            DoubleAnimation animation3 = new DoubleAnimation {
                To = 300, Duration = new Duration(TimeSpan.FromSeconds(1))
            };

            SequentialTimeline sequentialTimeline = new SequentialTimeline();

            sequentialTimeline.Children.Add(animation1);
            sequentialTimeline.Children.Add(animation2);
            sequentialTimeline.Children.Add(animation3);

            Storyboard storyboard = new Storyboard();

            storyboard.Children.Add(sequentialTimeline);

            FrameworkElement element = new FrameworkElement {
                Width = 0, Height = 0
            };

            Storyboard.SetTarget(animation1, element);
            Storyboard.SetTargetProperty(animation1, PropertyPath.FromDependencyProperty(FrameworkElement.WidthProperty));

            Storyboard.SetTarget(animation2, element);
            Storyboard.SetTargetProperty(animation2, PropertyPath.FromDependencyProperty(FrameworkElement.WidthProperty));

            Storyboard.SetTarget(animation3, element);
            Storyboard.SetTargetProperty(animation3, PropertyPath.FromDependencyProperty(FrameworkElement.WidthProperty));

            TestRootClock rootClock = new TestRootClock();

            element.SetAnimatableRootClock(new AnimatableRootClock(rootClock, true));
            storyboard.Begin(element);

            rootClock.Tick(TimeSpan.FromSeconds(0));
            Assert.AreEqual(0, element.Width);

            rootClock.Tick(TimeSpan.FromSeconds(0.9));
            Assert.AreEqual(90, element.Width);

            rootClock.Tick(TimeSpan.FromSeconds(1));
            Assert.AreEqual(200, element.Width);

            rootClock.Tick(TimeSpan.FromSeconds(1.5));
            Assert.AreEqual(250, element.Width);

            rootClock.Tick(TimeSpan.FromSeconds(2));
            Assert.AreEqual(300, element.Width);
        }
示例#3
0
        public void StoryboardBasicTest()
        {
            DoubleAnimation widthAnimation = new DoubleAnimation {
                To = 100
            };
            DoubleAnimation heightAnimation = new DoubleAnimation {
                From = 100
            };

            Storyboard storyboard = new Storyboard();

            storyboard.Children.Add(widthAnimation);
            storyboard.Children.Add(heightAnimation);

            FrameworkElement element = new FrameworkElement {
                Width = 0, Height = 0
            };

            Storyboard.SetTarget(widthAnimation, element);
            Storyboard.SetTargetProperty(widthAnimation, PropertyPath.FromDependencyProperty(FrameworkElement.WidthProperty));

            Storyboard.SetTarget(heightAnimation, element);
            Storyboard.SetTargetProperty(heightAnimation, PropertyPath.FromDependencyProperty(FrameworkElement.HeightProperty));

            TestRootClock rootClock = new TestRootClock();

            element.SetAnimatableRootClock(new AnimatableRootClock(rootClock, true));
            storyboard.Begin(element);

            rootClock.Tick(TimeSpan.FromSeconds(0));
            Assert.AreEqual(0, element.Width);
            Assert.AreEqual(100, element.Height);

            rootClock.Tick(TimeSpan.FromSeconds(0.1));
            Assert.AreEqual(10, element.Width);
            Assert.AreEqual(90, element.Height);

            rootClock.Tick(TimeSpan.FromSeconds(1));
            Assert.AreEqual(100, element.Width);
            Assert.AreEqual(0, element.Height);

            storyboard.Seek(element, TimeSpan.FromSeconds(0.5));
            rootClock.Tick(TimeSpan.FromSeconds(1));
            Assert.AreEqual(50, element.Width);
            Assert.AreEqual(50, element.Height);

            storyboard.Remove(element);
            rootClock.Tick(TimeSpan.FromSeconds(1));
            Assert.AreEqual(0, element.Width);
            Assert.AreEqual(0, element.Height);
        }
示例#4
0
        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));
        }
示例#5
0
        public void TimelineClockControlSeekTest()
        {
            TestRootClock rootClock = new TestRootClock();
            TestTimeline  timeline  = new TestTimeline();
            TimelineClock clock     = (TimelineClock)timeline.CreateClock();

            clock.Begin(rootClock);
            rootClock.Tick(TimeSpan.FromSeconds(0.1));
            Assert.AreEqual(ClockProgressState.Active, clock.CurrentState.ProgressState);
            Assert.AreEqual(0.1, clock.CurrentState.Progress);

            clock.SeekOffset(TimeSpan.FromSeconds(0.1));
            rootClock.Tick(TimeSpan.FromSeconds(0.2));
            Assert.AreEqual(0.1, clock.CurrentState.Progress);

            clock.Seek(TimeSpan.FromSeconds(0.9));
            rootClock.Tick(TimeSpan.FromSeconds(0.3));
            Assert.AreEqual(1, clock.CurrentState.Progress);
        }
示例#6
0
        public void TimelineClockControlBasicTest()
        {
            TestRootClock rootClock = new TestRootClock();
            TestTimeline  timeline  = new TestTimeline();
            TimelineClock clock     = (TimelineClock)timeline.CreateClock();

            rootClock.Tick(TimeSpan.FromSeconds(10));

            Assert.AreEqual(ClockProgressState.BeforeStarted, clock.CurrentState.ProgressState);
            Assert.AreEqual(0, clock.CurrentState.Progress);
            Assert.AreEqual(0, clock.CurrentState.Iteration);

            clock.Begin(rootClock);

            Assert.AreEqual(ClockProgressState.Active, clock.CurrentState.ProgressState);
            Assert.AreEqual(0, clock.CurrentState.Progress);

            rootClock.Tick(TimeSpan.FromSeconds(10.1));

            Assert.AreEqual(ClockProgressState.Active, clock.CurrentState.ProgressState);
            Assert.AreEqual(0.1, clock.CurrentState.Progress);

            clock.Pause();
            rootClock.Tick(TimeSpan.FromSeconds(10.2));

            Assert.AreEqual(ClockProgressState.Active, clock.CurrentState.ProgressState);
            Assert.AreEqual(0.1, clock.CurrentState.Progress);

            clock.Resume();
            rootClock.Tick(TimeSpan.FromSeconds(10.3));

            Assert.AreEqual(ClockProgressState.Active, clock.CurrentState.ProgressState);
            Assert.AreEqual(0.2, clock.CurrentState.Progress);

            clock.Stop();
            rootClock.Tick(TimeSpan.FromSeconds(10.4));

            Assert.AreEqual(ClockProgressState.AfterEnded, clock.CurrentState.ProgressState);
            Assert.AreEqual(1, clock.CurrentState.Progress);
        }
示例#7
0
        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));
        }
示例#8
0
        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));
        }