當前位置: 首頁>>代碼示例>>C#>>正文


C# DoubleAnimationUsingKeyFrames.GetCurrentValue方法代碼示例

本文整理匯總了C#中System.Windows.Media.Animation.DoubleAnimationUsingKeyFrames.GetCurrentValue方法的典型用法代碼示例。如果您正苦於以下問題:C# DoubleAnimationUsingKeyFrames.GetCurrentValue方法的具體用法?C# DoubleAnimationUsingKeyFrames.GetCurrentValue怎麽用?C# DoubleAnimationUsingKeyFrames.GetCurrentValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Windows.Media.Animation.DoubleAnimationUsingKeyFrames的用法示例。


在下文中一共展示了DoubleAnimationUsingKeyFrames.GetCurrentValue方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: DoubleAnimationKeyFrameRepeatTest

        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));
        }
開發者ID:highzion,項目名稱:Granular,代碼行數:32,代碼來源:DoubleAnimationTest.cs

示例2: MoveResourceInBounds

        private void MoveResourceInBounds(ResourceViewModel resourceViewModel)
        {
            Storyboard storyboard = new Storyboard();

            var view = (FrameworkElement)(desktopView.ItemContainerGenerator.ContainerFromItem(resourceViewModel));

            const double offset = 4;

            double left = resourceViewModel.Left;
            double right = left + view.ActualWidth;
            double top = resourceViewModel.Top;
            double bottom = top + view.ActualHeight;

            bool leftOutBound = left < 0;
            bool rightOutBound = right > desktopView.ActualWidth;
            bool topOutBound = top < 0;
            bool bottomOutBound = bottom > desktopView.ActualHeight;

            if (leftOutBound || rightOutBound)
            {
                double from = left;
                double to = (leftOutBound ? offset : (desktopView.ActualWidth - view.ActualWidth - offset));

                DoubleAnimationUsingKeyFrames animation = new DoubleAnimationUsingKeyFrames()
                {
                    Duration = TimeSpan.FromMilliseconds(125)
                };

                animation.KeyFrames.Add(new SplineDoubleKeyFrame(from, KeyTime.FromTimeSpan(TimeSpan.Zero)));
                animation.KeyFrames.Add(new SplineDoubleKeyFrame(to + ((leftOutBound ? offset : offset * -1) * 2), KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(80))));
                animation.KeyFrames.Add(new SplineDoubleKeyFrame(to, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(125))));

                AnimationClock clock = animation.CreateClock();
                clock.CurrentTimeInvalidated += (sender, e) =>
                {
                    double current = animation.GetCurrentValue(from, to, clock);
                    resourceViewModel.Left = current;
                };

                storyboard.Children.Add(animation);

                Storyboard.SetTargetProperty(animation, new PropertyPath(ResourceView.DummyLeftProperty));
            }

            if (topOutBound || bottomOutBound)
            {
                double from = top;
                double to = (topOutBound ? offset : (desktopView.ActualHeight - view.ActualHeight - offset));

                DoubleAnimationUsingKeyFrames animation = new DoubleAnimationUsingKeyFrames()
                {
                    Duration = TimeSpan.FromMilliseconds(125)
                };

                animation.KeyFrames.Add(new SplineDoubleKeyFrame(from, KeyTime.FromTimeSpan(TimeSpan.Zero)));
                animation.KeyFrames.Add(new SplineDoubleKeyFrame(to + ((topOutBound ? offset : offset * -1) * 2), KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(80))));
                animation.KeyFrames.Add(new SplineDoubleKeyFrame(to, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(125))));

                AnimationClock clock = animation.CreateClock();
                clock.CurrentTimeInvalidated += (sender, e) =>
                {
                    double current = animation.GetCurrentValue(from, to, clock);
                    resourceViewModel.Top = current;
                };

                storyboard.Children.Add(animation);

                Storyboard.SetTargetProperty(animation, new PropertyPath(ResourceView.DummyTopProperty));
            }

            this.BeginStoryboard(storyboard);
        }
開發者ID:nevasion,項目名稱:gandi-desktop,代碼行數:72,代碼來源:DesktopView.xaml.cs


注:本文中的System.Windows.Media.Animation.DoubleAnimationUsingKeyFrames.GetCurrentValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。