diff --git a/UICompositionAnimations/CompositionExtensions.cs b/UICompositionAnimations/CompositionExtensions.cs index 0417a25..47a44e6 100644 --- a/UICompositionAnimations/CompositionExtensions.cs +++ b/UICompositionAnimations/CompositionExtensions.cs @@ -836,6 +836,62 @@ public static async Task StartCompositionRollAnimationAsync(this FrameworkElemen #endregion + #region Expression animations + + /// + /// Creates and starts an animation on the target element that binds either the X or Y axis of the source + /// + /// The source control to use + /// The target that will be animated + /// The scrolling axis of the source + /// The scrolling axis of the target element + /// Indicates whether or not to invert the animation from the source + [NotNull] + public static ExpressionAnimation StartExpressionAnimation( + [NotNull] this ScrollViewer scroller, [NotNull] UIElement target, + TranslationAxis sourceXY, TranslationAxis targetXY, bool invertSourceAxis = false) + { + CompositionPropertySet scrollSet = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scroller); + String sign = invertSourceAxis ? "-" : String.Empty; + ExpressionAnimation animation = scrollSet.Compositor.CreateExpressionAnimation($"{sign}scroll.Translation.{sourceXY}"); + animation.SetReferenceParameter("scroll", scrollSet); + target.GetVisual().StartAnimation($"Offset.{targetXY}", animation); + return animation; + } + + /// + /// Creates and starts an animation on the target element, with the addition of a scalar parameter in the resulting + /// + /// The source control to use + /// The target that will be animated + /// The scrolling axis of the source + /// The scrolling axis of the target element + /// An additional parameter that will be included in the expression animation + /// Indicates whether or not to invert the animation from the source + [NotNull] + public static ExpressionAnimation StartExpressionAnimation( + [NotNull] this ScrollViewer scroller, [NotNull] UIElement target, + TranslationAxis sourceXY, TranslationAxis targetXY, + float parameter, bool invertSourceAxis = false) + { + // Get the property set and setup the scroller offset sign + CompositionPropertySet scrollSet = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scroller); + String sign = invertSourceAxis ? "-" : "+"; + + // Prepare the second property set to insert the additional parameter + CompositionPropertySet properties = scroller.GetVisual().Compositor.CreatePropertySet(); + properties.InsertScalar(nameof(parameter), parameter); + + // Create and start the animation + ExpressionAnimation animation = scrollSet.Compositor.CreateExpressionAnimation($"{nameof(properties)}.{nameof(parameter)} {sign} scroll.Translation.{sourceXY}"); + animation.SetReferenceParameter("scroll", scrollSet); + animation.SetReferenceParameter(nameof(properties), properties); + target.GetVisual().StartAnimation($"Offset.{targetXY}", animation); + return animation; + } + + #endregion + #region Shadows /// diff --git a/UICompositionAnimations/Properties/AssemblyInfo.cs b/UICompositionAnimations/Properties/AssemblyInfo.cs index 2919549..fd23c33 100644 --- a/UICompositionAnimations/Properties/AssemblyInfo.cs +++ b/UICompositionAnimations/Properties/AssemblyInfo.cs @@ -23,6 +23,6 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.3.3.0")] +[assembly: AssemblyVersion("2.4.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: ComVisible(false)] \ No newline at end of file diff --git a/UICompositionAnimations/UICompositionAnimations.nuspec b/UICompositionAnimations/UICompositionAnimations.nuspec index c8a93a4..082455d 100644 --- a/UICompositionAnimations/UICompositionAnimations.nuspec +++ b/UICompositionAnimations/UICompositionAnimations.nuspec @@ -2,14 +2,14 @@ Sergio0694.UWP.UICompositionAnimations - 2.3.3.0 + 2.4.0.0 UICompositionAnimations A wrapper UWP PCL to work with Windows.UI.Composition and XAML animations, and Win2D effects Sergio Pedri Sergio Pedri https://github.com/Sergio0694/UICompositionAnimations false - Minor bug fixes + Added the ability to create and start composition expression animations Copyright 2017 uwp composition animations xaml csharp windows winrt universal app ui win2d graphics