public static ColorAnimationUsingKeyFrames BlinkAnimation(Color startColor)
        {
            var toRed = new DiscreteColorKeyFrame
            {
                KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(100)),
                Value   = Colors.Red
            };
            var keepRed = new DiscreteColorKeyFrame
            {
                KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500)),
                Value   = Colors.Red
            };
            var back = new LinearColorKeyFrame
            {
                KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(1500)),
                Value   = startColor
            };

            var colorAnimationUsingKeyFrames = new ColorAnimationUsingKeyFrames();
            ColorKeyFrameCollection colorKeyFrameCollection = colorAnimationUsingKeyFrames.KeyFrames;

            colorKeyFrameCollection.Add(toRed);
            colorKeyFrameCollection.Add(keepRed);
            colorKeyFrameCollection.Add(back);

            return(colorAnimationUsingKeyFrames);
        }
        public static ColorAnimationUsingKeyFrames FreeAnimation(Color startColor)
        {
            // mutued from XAML example at https://docs.microsoft.com/en-us/uwp/api/Windows.UI.Xaml.Media.Animation.ColorAnimation

            var linearColorKeyFrame = new LinearColorKeyFrame
            {
                KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(2000)),
                Value   = Colors.Red
            };
            var discreteColorKeyFrame = new DiscreteColorKeyFrame
            {
                KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(2500)),
                Value   = Colors.Yellow
            };
            var splineColorKeyFrame = new SplineColorKeyFrame
            {
                KeyTime   = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(4500)),
                Value     = startColor,
                KeySpline = new KeySpline {
                    ControlPoint1 = new Point(0.6, 0.0), ControlPoint2 = new Point(0.9, 0.0)
                }
            };

            var colorAnimationUsingKeyFrames = new ColorAnimationUsingKeyFrames();
            ColorKeyFrameCollection colorKeyFrameCollection = colorAnimationUsingKeyFrames.KeyFrames;

            colorKeyFrameCollection.Add(linearColorKeyFrame);
            colorKeyFrameCollection.Add(discreteColorKeyFrame);
            colorKeyFrameCollection.Add(splineColorKeyFrame);

            return(colorAnimationUsingKeyFrames);
        }
Ejemplo n.º 3
0
        private static ColorKeyFrame CreateColorKeyFrmas(KeyFrames <Color> Model)
        {
            ColorKeyFrame frame = null;

            switch (Model.Type)
            {
            case KeyFramesType.Spline: frame = new SplineColorKeyFrame()
            {
                    KeySpline = Model.Spline
            }; break;

            case KeyFramesType.Linear: frame = new LinearColorKeyFrame(); break;

            case KeyFramesType.Easing: frame = new EasingColorKeyFrame()
            {
                    EasingFunction = Model.EasingFunction
            }; break;

            case KeyFramesType.Discrete: frame = new DiscreteColorKeyFrame(); break;

            default: break;
            }
            frame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(Model.KeyTime));
            frame.Value   = Model.Value;
            return(frame);
        }
        public static ColorAnimationUsingKeyFrames AddDiscreteKeyFrame(
            this ColorAnimationUsingKeyFrames animation,
            double seconds, Color value)
        {
            var keyFrame = new DiscreteColorKeyFrame
            {
                KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(seconds)),
                Value   = value,
            };

            animation.KeyFrames.Add(keyFrame);
#if NETFX_CORE || WINDOWS_81_PORTABLE
            animation.EnableDependentAnimation = true;
#endif
            return(animation);
        }
Ejemplo n.º 5
0
        private ColorAnimationUsingKeyFrames getColorAnimationFrames(Color firstColor, Color secondColor)
        {
            ColorAnimationUsingKeyFrames animationFrames = new ColorAnimationUsingKeyFrames();

            for (int i = 1; i < 6; i++)
            {
                if (i % 2 == 0)
                {
                    DiscreteColorKeyFrame frame = new DiscreteColorKeyFrame();
                    frame.KeyTime = new TimeSpan(0, 0, 0, 0, i * 250);
                    frame.Value   = firstColor;
                    animationFrames.KeyFrames.Add(frame);
                }
                else
                {
                    DiscreteColorKeyFrame frame = new DiscreteColorKeyFrame();
                    frame.KeyTime = new TimeSpan(0, 0, 0, 0, i * 250);
                    frame.Value   = secondColor;
                    animationFrames.KeyFrames.Add(frame);
                }
            }
            return(animationFrames);
        }