Vector2KeyFrameAnimation CreateAnimation() { Vector2KeyFrameAnimation animation = _compositor.CreateVector2KeyFrameAnimation(); animation.InsertExpressionKeyFrame(0f, "this.StartingValue"); animation.InsertExpressionKeyFrame(1f, "this.FinalValue"); animation.Target = "Size"; animation.Duration = TimeSpan.FromSeconds(1); return(animation); }
/// <summary> /// Creates a <see cref="ScalarKeyFrameAnimation"/> instance with the given parameters to on a target element, using an expression animation /// </summary> /// <param name="compositor">The current <see cref="Compositor"/> instance used to create the animation</param> /// <param name="from">The optional starting value for the animation</param> /// <param name="to">A string that indicates the final value for the animation</param> /// <param name="duration">The animation duration</param> /// <param name="delay">The optional initial delay for the animation</param> /// <param name="ease">The optional easing function for the animation</param> public static Vector2KeyFrameAnimation CreateVector2KeyFrameAnimation( this Compositor compositor, Vector2? from, string to, TimeSpan duration, TimeSpan? delay, CompositionEasingFunction ease = null) { // Set duration and delay time Vector2KeyFrameAnimation ani = compositor.CreateVector2KeyFrameAnimation(); ani.Duration = duration; if (delay.HasValue) ani.DelayTime = delay.Value; // Insert "to" and "from" keyframes ani.InsertExpressionKeyFrame(1, to, ease ?? compositor.CreateLinearEasingFunction()); if (from.HasValue) ani.InsertKeyFrame(0, from.Value); return ani; }