Exemplo n.º 1
0
        /// <summary>
        /// Animates the series.
        /// </summary>
        internal override void Animate()
        {
            int i = 0;

            // WPF-25124 Animation not working properly when resize the window.
            if (this.AnimationStoryboard != null)
            {
                AnimationStoryboard.Stop();
                if (!this.canAnimate)
                {
                    this.ResetAdornmentAnimationState();
                    return;
                }
            }

            this.AnimationStoryboard = new Storyboard();
            foreach (LineSegment3D segment in this.Segments)
            {
                var dblAnimationKeyFrames = new DoubleAnimationUsingKeyFrames();
                var min      = YValues.Min();
                var keyFrame = new SplineDoubleKeyFrame
                {
                    KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)),
                    Value   = double.IsNaN(min) ? YValues.Where(e => !double.IsNaN(e)).Min() : min
                };
                dblAnimationKeyFrames.KeyFrames.Add(keyFrame);
                keyFrame = new SplineDoubleKeyFrame
                {
                    KeyTime = KeyTime.FromTimeSpan(AnimationDuration),
                    Value   = YValues.Max()
                };
                var keySpline = new KeySpline
                {
                    ControlPoint1 = new Point(0.64, 0.84),
                    ControlPoint2 = new Point(0.67, 0.95)
                };
                keyFrame.KeySpline = keySpline;
                dblAnimationKeyFrames.KeyFrames.Add(keyFrame);
                Storyboard.SetTargetProperty(dblAnimationKeyFrames, "LineSegment3D.Y");
                dblAnimationKeyFrames.EnableDependentAnimation = true;
                Storyboard.SetTarget(dblAnimationKeyFrames, segment);
                AnimationStoryboard.Children.Add(dblAnimationKeyFrames);

                if (this.AdornmentsInfo != null)
                {
                    double secondsPerPoint = AnimationDuration.TotalSeconds / YValues.Count;
                    secondsPerPoint *= 2;

                    foreach (FrameworkElement label in this.AdornmentsInfo.LabelPresenters)
                    {
                        DoubleAnimation keyFrames1 = new DoubleAnimation()
                        {
                            From      = 0.5,
                            To        = 1,
                            Duration  = TimeSpan.FromSeconds(AnimationDuration.TotalSeconds / 2),
                            BeginTime = TimeSpan.FromSeconds(i * secondsPerPoint)
                        };

                        Storyboard.SetTargetProperty(keyFrames1, "(UIElement.Opacity)");
                        Storyboard.SetTarget(keyFrames1, label);
                        AnimationStoryboard.Children.Add(keyFrames1);

                        i++;
                    }
                }
            }

            AnimationStoryboard.Begin();
        }