public void SequentialTimelineClockStoryboardTest()
        {
            DoubleAnimation animation1 = new DoubleAnimation { To = 100, Duration = Duration.FromTimeSpan(TimeSpan.FromSeconds(1)) };
            DoubleAnimation animation2 = new DoubleAnimation { To = 200, Duration = Duration.FromTimeSpan(TimeSpan.FromSeconds(0)) };
            DoubleAnimation animation3 = new DoubleAnimation { To = 300, Duration = Duration.FromTimeSpan(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);
        }
Example #2
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);
        }
        public void AnimatableRootClockConnectionTest()
        {
            TestRootClock rootClock = new TestRootClock();

            FrameworkElement element = new FrameworkElement();
            element.SetAnimatableRootClock(new AnimatableRootClock(rootClock, false));

            Assert.AreEqual(0, rootClock.Clocks.Count());
            Assert.IsFalse(element.IsVisible);

            element.IsRootElement = true;
            Assert.IsTrue(element.IsVisible);

            DoubleAnimation animation = new DoubleAnimation { From = 0, To = 1 };

            element.BeginAnimation(FrameworkElement.WidthProperty, animation);
            Assert.AreEqual(1, rootClock.Clocks.Count());

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

            element.IsRootElement = false;
            Assert.IsFalse(element.IsVisible);
            Assert.AreEqual(0, rootClock.Clocks.Count());

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

            element.IsRootElement = true;
            Assert.IsTrue(element.IsVisible);
            Assert.AreEqual(1, rootClock.Clocks.Count());
            Assert.AreEqual(0.2, element.Width);

            rootClock.Tick(TimeSpan.FromSeconds(2));
            Assert.AreEqual(0, rootClock.Clocks.Count());

            element.IsRootElement = false;
            element.IsRootElement = true;
            Assert.AreEqual(0, rootClock.Clocks.Count());
        }