Пример #1
0
        public static void BeginAnimation(this IAnimatable animatable, DependencyProperty dependencyProperty, AnimationTimeline animation, HandoffBehavior handoffBehavior = HandoffBehavior.SnapshotAndReplace, object layerOwner = null)
        {
            AnimationTimelineClock animationClock = (AnimationTimelineClock)animation.CreateClock();

            animatable.ApplyAnimationClock(dependencyProperty, animationClock, handoffBehavior, layerOwner);
            animationClock.Begin(animatable.RootClock);
        }
Пример #2
0
        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);
            }
        }