Beispiel #1
0
 /// <summary>
 /// Creates and starts a scalar animation on the current <see cref="CompositionObject"/>
 /// </summary>
 /// <param name="target">The target to animate</param>
 /// <param name="propertyPath">The path that identifies the property to animate</param>
 /// <param name="from">The optional starting value for the animation</param>
 /// <param name="to">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 void BeginScalarAnimation(
     [NotNull] this CompositionObject target,
     [NotNull] string propertyPath,
     float?from, float to,
     TimeSpan duration, TimeSpan?delay,
     [CanBeNull] CompositionEasingFunction ease = null)
 {
     target.StartAnimation(propertyPath, target.Compositor.CreateScalarKeyFrameAnimation(from, to, duration, delay, ease));
 }
Beispiel #2
0
 /// <summary>
 /// Creates and starts a <see cref="Vector3"/> animation on the current <see cref="CompositionObject"/>
 /// </summary>
 /// <param name="target">The target to animate</param>
 /// <param name="propertyPath">The path that identifies the property to animate</param>
 /// <param name="from">The optional starting value for the animation</param>
 /// <param name="to">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 void BeginVector3Animation(
     this CompositionObject target,
     string propertyPath,
     Vector3?from, Vector3 to,
     TimeSpan duration, TimeSpan?delay,
     CompositionEasingFunction ease = null)
 {
     target.StartAnimation(propertyPath, target.Compositor.CreateVector3KeyFrameAnimation(from, to, duration, delay, ease));
 }
Beispiel #3
0
        /// <summary>
        /// Starts an <see cref="ExpressionAnimation"/> to keep the size of the source <see cref="CompositionObject"/> in sync with the target <see cref="UIElement"/>
        /// </summary>
        /// <param name="source">The <see cref="CompositionObject"/> to start the animation on</param>
        /// <param name="target">The target <see cref="UIElement"/> to read the size updates from</param>
        public static void BindSize(this CompositionObject source, UIElement target)
        {
            Visual visual = target.GetVisual();
            ExpressionAnimation bindSizeAnimation = Window.Current.Compositor.CreateExpressionAnimation($"{nameof(visual)}.Size");

            bindSizeAnimation.SetReferenceParameter(nameof(visual), visual);

            // Start the animation
            source.StartAnimation("Size", bindSizeAnimation);
        }
Beispiel #4
0
 void StartAnimations(Wd.CompositionObject source, Wc.CompositionObject target)
 {
     foreach (var animator in source.Animators)
     {
         var animation = GetCompositionAnimation(animator.Animation);
         target.StartAnimation(animator.AnimatedProperty, animation);
         var controller = animator.Controller;
         if (controller != null)
         {
             var animationController = GetAnimationController(controller);
             if (controller.IsPaused)
             {
                 animationController.Pause();
             }
         }
     }
 }
Beispiel #5
0
        /// <summary>
        /// Starts an animation on the given property of a <see cref="CompositionObject"/>
        /// </summary>
        /// <param name="target">The target <see cref="CompositionObject"/></param>
        /// <param name="property">The name of the property to animate</param>
        /// <param name="value">The final value of the property</param>
        /// <param name="duration">The animation duration</param>
        public static Task StartAnimationAsync([NotNull] this CompositionObject target, string property, float value, TimeSpan duration)
        {
            // Stop previous animations
            target.StopAnimation(property);

            // Setup the animation
            ScalarKeyFrameAnimation animation = target.Compositor.CreateScalarKeyFrameAnimation();

            animation.InsertKeyFrame(1f, value);
            animation.Duration = duration;

            // Get the batch and start the animations
            CompositionScopedBatch        batch = target.Compositor.CreateScopedBatch(CompositionBatchTypes.Animation);
            TaskCompletionSource <object> tcs   = new TaskCompletionSource <object>();

            batch.Completed += (s, e) => tcs.SetResult(null);
            target.StartAnimation(property, animation);
            batch.End();
            return(tcs.Task);
        }
 public static void BeginVector3Animation(this CompositionObject compObj, string propertyPath, Vector3 to, Vector3?from, TimeSpan duration, TimeSpan?delay, CompositionEasingFunction ease)
 {
     compObj.StartAnimation(propertyPath,
                            compObj.Compositor.CreateVector3KeyFrameAnimation(to, from, duration, delay, ease));
 }