Пример #1
0
        public void StartColorAnimation()
        {
            storyboard_colors = new Storyboard();


            AnimationData _animationData = new AnimationData(this);

            _animationData.GenerateNextData(this.animationData);
            this.animationData = _animationData;

            {
                ColorAnimation gradientStopColorAnimation = new ColorAnimation();

                gradientStopColorAnimation.To       = animationData.color1;
                gradientStopColorAnimation.Duration = animationData.AnimationTime;

                Storyboard.SetTargetName(gradientStopColorAnimation, "GradientStop1");
                Storyboard.SetTargetProperty(gradientStopColorAnimation, new PropertyPath(GradientStop.ColorProperty));

                storyboard_colors.Children.Add(gradientStopColorAnimation);
            }

            {
                ColorAnimation gradientStopColorAnimation = new ColorAnimation();

                gradientStopColorAnimation.To       = animationData.color2;
                gradientStopColorAnimation.Duration = animationData.AnimationTime;

                Storyboard.SetTargetName(gradientStopColorAnimation, "GradientStop2");
                Storyboard.SetTargetProperty(gradientStopColorAnimation, new PropertyPath(GradientStop.ColorProperty));

                storyboard_colors.Children.Add(gradientStopColorAnimation);
            }

            {
                PointAnimation pointAnimation = new PointAnimation();

                pointAnimation.To       = animationData.StartPoint;
                pointAnimation.Duration = animationData.AnimationTime;

                Storyboard.SetTargetName(pointAnimation, "Background");
                Storyboard.SetTargetProperty(pointAnimation, new PropertyPath(LinearGradientBrush.StartPointProperty));

                storyboard_colors.Children.Add(pointAnimation);
            }

            {
                PointAnimation pointAnimation = new PointAnimation();

                pointAnimation.To       = animationData.EndPoint;
                pointAnimation.Duration = animationData.AnimationTime;

                Storyboard.SetTargetName(pointAnimation, "Background");
                Storyboard.SetTargetProperty(pointAnimation, new PropertyPath(LinearGradientBrush.EndPointProperty));

                storyboard_colors.Children.Add(pointAnimation);
            }

            storyboard_colors.Completed += new EventHandler((sender, args) =>
            {
                //storyboard.Remove(this.containingElement);
                //storyboard = null;
                StartColorAnimation();
            });

            storyboard_colors.Begin(this.containingElement, true);

            this.ColorStoryboard = storyboard_colors;
        }