/// <inheritdoc/> protected override IAnimationBuilder OnScale(double?from, double to, Easing ease) { AnimationFactories.Add(duration => TargetTransform.CreateDoubleAnimation(nameof(CompositeTransform.ScaleX), from, to, duration, ease)); AnimationFactories.Add(duration => TargetTransform.CreateDoubleAnimation(nameof(CompositeTransform.ScaleY), from, to, duration, ease)); return(this); }
/// <inheritdoc/> protected override IAnimationBuilder OnClip(Side side, double?from, double to, Easing ease) { AnimationFactories.Add(duration => { // Stop the animation and get the easing function string property; switch (side) { case Side.Top: property = nameof(InsetClip.TopInset); break; case Side.Bottom: property = nameof(InsetClip.BottomInset); break; case Side.Right: property = nameof(InsetClip.RightInset); break; case Side.Left: property = nameof(InsetClip.LeftInset); break; default: throw new ArgumentException("Invalid side", nameof(side)); } InsetClip clip = TargetVisual.Clip as InsetClip ?? (TargetVisual.Clip = TargetVisual.Compositor.CreateInsetClip()).To <InsetClip>(); clip.StopAnimation(property); CompositionEasingFunction easingFunction = clip.GetEasingFunction(ease); // Create and return the animation ScalarKeyFrameAnimation animation = clip.Compositor.CreateScalarKeyFrameAnimation((float?)from, (float)to, duration, null, easingFunction); clip.StartAnimation(property, animation); }); return(this); }
/// <inheritdoc/> protected override IAnimationBuilder OnTranslation(Vector2?from, Vector2 to, Easing ease) { AnimationFactories.Add(duration => TargetTransform.CreateDoubleAnimation(nameof(CompositeTransform.TranslateX), from?.X, to.X, duration, ease)); AnimationFactories.Add(duration => TargetTransform.CreateDoubleAnimation(nameof(CompositeTransform.TranslateY), from?.Y, to.Y, duration, ease)); return(this); }
/// <summary> /// Schedules a scalar animation targeting the current <see cref="Visual"/> item /// </summary> /// <param name="property">The target <see cref="Visual"/> property to animate</param> /// <param name="from">The optional starting value for the scalar animation</param> /// <param name="to">The target value for the scalar animation</param> /// <param name="ease">The easing function to use for the scalar animation</param> private IAnimationBuilder OnScalarAnimation(string property, double?from, double to, Easing ease) { AnimationFactories.Add(duration => { // Stop the animation and get the easing function TargetVisual.StopAnimation(property); CompositionEasingFunction easingFunction = TargetVisual.GetEasingFunction(ease); // Create and return the animation ScalarKeyFrameAnimation animation = TargetVisual.Compositor.CreateScalarKeyFrameAnimation((float?)from, (float)to, duration, null, easingFunction); TargetVisual.StartAnimation(property, animation); }); return(this); }
/// <inheritdoc/> protected override IAnimationBuilder OnSize(Vector2?from, Vector2 to, Easing ease = Easing.Linear) { if (!(TargetElement is FrameworkElement element)) { throw new InvalidOperationException("Can't animate the size of an item that's not a framework element"); } double? fromX = double.IsNaN(element.Width) ? (double?)element.ActualWidth : from?.X, fromY = double.IsNaN(element.Height) ? (double?)element.ActualHeight : from?.Y; AnimationFactories.Add(duration => TargetTransform.CreateDoubleAnimation(nameof(FrameworkElement.Width), fromX, to.X, duration, ease, true)); AnimationFactories.Add(duration => TargetTransform.CreateDoubleAnimation(nameof(FrameworkElement.Height), fromY, to.Y, duration, ease, true)); return(this); }
/// <summary> /// Schedules a vector animation targeting the current <see cref="Visual"/> item /// </summary> /// <param name="property">The target <see cref="Visual"/> property to animate</param> /// <param name="from">The optional starting value for the vector animation</param> /// <param name="to">The target value for the vector animation</param> /// <param name="ease">The easing function to use for the vector animation</param> private IAnimationBuilder OnVector3Animation(string property, Vector2?from, Vector2 to, Easing ease) { AnimationFactories.Add(duration => { // Stop the animation and get the easing function TargetVisual.StopAnimation(property); CompositionEasingFunction easingFunction = TargetVisual.GetEasingFunction(ease); // Create and return the animation Vector3?from3 = from == null ? default(Vector3?) : new Vector3(from.Value, 0); Vector3 to3 = new Vector3(to, 0); Vector3KeyFrameAnimation animation = TargetVisual.Compositor.CreateVector3KeyFrameAnimation(from3, to3, duration, null, easingFunction); TargetVisual.StartAnimation(property, animation); }); return(this); }
/// <inheritdoc/> protected override IAnimationBuilder OnSize(Axis axis, double?from, double to, Easing ease) { if (!(TargetElement is FrameworkElement element)) { throw new InvalidOperationException("Can't animate the size of an item that's not a framework element"); } AnimationFactories.Add(duration => { switch (axis) { case Axis.X: return(TargetElement.CreateDoubleAnimation(nameof(FrameworkElement.Width), double.IsNaN(element.Width) ? element.ActualWidth : from, to, duration, ease, true)); case Axis.Y: return(TargetElement.CreateDoubleAnimation(nameof(FrameworkElement.Height), double.IsNaN(element.Height) ? element.ActualHeight : from, to, duration, ease, true)); default: throw new ArgumentException($"Invalid axis: {axis}", nameof(axis)); } }); return(this); }
/// <inheritdoc/> protected override IAnimationBuilder OnTranslation(Axis axis, double?from, double to, Easing ease) { AnimationFactories.Add(duration => TargetTransform.CreateDoubleAnimation($"Translate{axis}", from, to, duration, ease)); return(this); }
/// <inheritdoc/> protected override IAnimationBuilder OnOpacity(double?from, double to, Easing ease) { AnimationFactories.Add(duration => TargetElement.CreateDoubleAnimation(nameof(UIElement.Opacity), from, to, duration, ease)); return(this); }