diff --git a/WinUIGallery/Assets/AnimatedVisuals/LottieLogo1.cs b/WinUIGallery/Assets/AnimatedVisuals/LottieLogo1.cs index 84ee873e7..1d0bd5001 100644 --- a/WinUIGallery/Assets/AnimatedVisuals/LottieLogo1.cs +++ b/WinUIGallery/Assets/AnimatedVisuals/LottieLogo1.cs @@ -9,8 +9,8 @@ using System; using System.Numerics; using Microsoft.Graphics.Canvas.Geometry; -using Microsoft.UI.Composition; using Microsoft.UI.Xaml.Controls; +using Windows.UI.Composition; namespace AnimatedVisuals; diff --git a/WinUIGallery/Controls/ControlExample.xaml b/WinUIGallery/Controls/ControlExample.xaml index 46bb3a4db..aef8ad3f6 100644 --- a/WinUIGallery/Controls/ControlExample.xaml +++ b/WinUIGallery/Controls/ControlExample.xaml @@ -2,7 +2,6 @@ x:Class="WinUIGallery.Controls.ControlExample" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:animations="using:CommunityToolkit.WinUI.Animations" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="using:WinUIGallery.Controls" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" @@ -12,32 +11,6 @@ d:DesignWidth="1000" IsTabStop="False" mc:Ignorable="d"> - - - - - - - - - - @@ -190,13 +163,10 @@ Text="C#" /> - (); this.Loaded += ControlExample_Loaded; } diff --git a/WinUIGallery/Controls/OpacityMaskView.xaml.cs b/WinUIGallery/Controls/OpacityMaskView.xaml.cs index 4545b42dd..4fd76c188 100644 --- a/WinUIGallery/Controls/OpacityMaskView.xaml.cs +++ b/WinUIGallery/Controls/OpacityMaskView.xaml.cs @@ -1,12 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using Microsoft.UI.Composition; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Hosting; using Microsoft.UI.Xaml.Media; using System.Numerics; +using Windows.UI.Composition; namespace WinUIGallery.Controls; @@ -30,7 +30,7 @@ public partial class OpacityMaskView : ContentControl private const string MaskContainerTemplateName = "PART_MaskContainer"; private const string RootGridTemplateName = "PART_RootGrid"; - private readonly Compositor _compositor = CompositionTarget.GetCompositorForCurrentThread(); + private readonly Compositor _compositor = Microsoft.UI.Xaml.Media.CompositionTarget.GetCompositorForCurrentThread(); private CompositionBrush? _mask; private CompositionMaskBrush? _maskBrush; diff --git a/WinUIGallery/Helpers/SystemCompositionAnimations.cs b/WinUIGallery/Helpers/SystemCompositionAnimations.cs new file mode 100644 index 000000000..dfa83f1e5 --- /dev/null +++ b/WinUIGallery/Helpers/SystemCompositionAnimations.cs @@ -0,0 +1,71 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Hosting; +using System; +using System.Numerics; +using Windows.UI.Composition; + +namespace WinUIGallery.Helpers; + +internal static class SystemCompositionAnimations +{ + public static void SetImplicitShowHide(UIElement element) + { + Compositor compositor = ElementCompositionPreview.GetElementVisual(element).Compositor; + + ElementCompositionPreview.SetImplicitShowAnimation( + element, + CreateAnimationGroup( + compositor, + new Vector3(0, 24, 0), + Vector3.Zero, + 0, + 1, + TimeSpan.FromMilliseconds(400), + TimeSpan.FromMilliseconds(200))); + + ElementCompositionPreview.SetImplicitHideAnimation( + element, + CreateAnimationGroup( + compositor, + Vector3.Zero, + new Vector3(0, 24, 0), + 1, + 0, + TimeSpan.FromMilliseconds(200), + TimeSpan.FromMilliseconds(100))); + } + + private static CompositionAnimationGroup CreateAnimationGroup( + Compositor compositor, + Vector3 offsetFrom, + Vector3 offsetTo, + float opacityFrom, + float opacityTo, + TimeSpan offsetDuration, + TimeSpan opacityDuration) + { + CubicBezierEasingFunction easing = compositor.CreateCubicBezierEasingFunction( + new Vector2(0, 0), + new Vector2(0.58f, 1)); + + Vector3KeyFrameAnimation offset = compositor.CreateVector3KeyFrameAnimation(); + offset.Target = "Offset"; + offset.InsertKeyFrame(0, offsetFrom); + offset.InsertKeyFrame(1, offsetTo, easing); + offset.Duration = offsetDuration; + + ScalarKeyFrameAnimation opacity = compositor.CreateScalarKeyFrameAnimation(); + opacity.Target = "Opacity"; + opacity.InsertKeyFrame(0, opacityFrom); + opacity.InsertKeyFrame(1, opacityTo, easing); + opacity.Duration = opacityDuration; + + CompositionAnimationGroup group = compositor.CreateAnimationGroup(); + group.Add(offset); + group.Add(opacity); + return group; + } +} diff --git a/WinUIGallery/Pages/HomePage.xaml b/WinUIGallery/Pages/HomePage.xaml index 4ab107160..f7e15f618 100644 --- a/WinUIGallery/Pages/HomePage.xaml +++ b/WinUIGallery/Pages/HomePage.xaml @@ -13,7 +13,6 @@ x:Class="WinUIGallery.Pages.HomePage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:animations="using:CommunityToolkit.WinUI.Animations" xmlns:controls="using:WinUIGallery.Controls" xmlns:local="using:WinUIGallery.Pages" xmlns:toolkit="using:CommunityToolkit.WinUI.Controls" @@ -21,31 +20,6 @@ 8 - - - - - - - - - @@ -83,8 +57,6 @@ - + - +