Exemple #1
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);
            }
        }