예제 #1
0
            public void Attach(FrameworkElement element)
            {
                TextBlock textBlock = new TextBlock();

                textBlock.SetValue(TextBlock.TextProperty, new Binding {
                    Source = element, Path = PropertyPath.FromDependencyProperty(ContentProperty), Mode = BindingMode.OneWay, Converter = ToStringConverter.Default
                });

                element.TemplateChild = textBlock;
            }
예제 #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);
        }