Merge pull request #4274 from Sergio0694/bugfix/implicit-animations-reset

Bugfix/implicit animations reset
This commit is contained in:
Michael Hawker MSFT (XAML Llama) 2021-09-24 19:19:37 -07:00 коммит произвёл GitHub
Родитель d775ea406d 4612a38f2a
Коммит fef65a5f3c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 57 добавлений и 24 удалений

Просмотреть файл

@ -5,6 +5,7 @@
using System;
using System.Numerics;
using Microsoft.Toolkit.Uwp.UI;
using Microsoft.Toolkit.Uwp.UI.Animations;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Hosting;
@ -18,6 +19,8 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
{
private Random _random = new Random();
private UIElement _element;
private ImplicitAnimationSet _animationSet;
private bool _areAnimationsToggled;
public ImplicitAnimationsPage()
{
@ -28,6 +31,8 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
public void OnXamlRendered(FrameworkElement control)
{
_element = control.FindChild("Element");
_animationSet = Implicit.GetAnimations(_element);
_areAnimationsToggled = true;
}
private void Load()
@ -60,6 +65,16 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
1);
}
});
SampleController.Current.RegisterNewCommand("Toggle animations", (sender, args) =>
{
if (_element != null)
{
Implicit.SetAnimations(_element, _areAnimationsToggled ? null : _animationSet);
_areAnimationsToggled = !_areAnimationsToggled;
}
});
}
}
}

Просмотреть файл

@ -53,7 +53,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations
if (collection is null)
{
element.SetValue(ShowAnimationsProperty, collection = new());
element.SetValue(ShowAnimationsProperty, collection = new ImplicitAnimationSet());
}
return collection;
@ -80,7 +80,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations
if (collection is null)
{
element.SetValue(HideAnimationsProperty, collection = new());
element.SetValue(HideAnimationsProperty, collection = new ImplicitAnimationSet());
}
return collection;
@ -107,7 +107,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations
if (collection is null)
{
element.SetValue(AnimationsProperty, collection = new());
element.SetValue(AnimationsProperty, collection = new ImplicitAnimationSet());
}
return collection;
@ -145,15 +145,21 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations
oldCollection.AnimationsChanged -= OnAnimationsChanged;
}
if (d is UIElement element &&
e.NewValue is ImplicitAnimationSet collection)
if (d is UIElement element)
{
collection.ParentReference = new(element);
collection.AnimationsChanged -= OnAnimationsChanged;
collection.AnimationsChanged += OnAnimationsChanged;
if (e.NewValue is ImplicitAnimationSet collection)
{
collection.ParentReference = new(element);
collection.AnimationsChanged -= OnAnimationsChanged;
collection.AnimationsChanged += OnAnimationsChanged;
ElementCompositionPreview.SetIsTranslationEnabled(element, true);
ElementCompositionPreview.SetImplicitShowAnimation(element, collection.GetCompositionAnimationGroup(element));
ElementCompositionPreview.SetIsTranslationEnabled(element, true);
ElementCompositionPreview.SetImplicitShowAnimation(element, collection.GetCompositionAnimationGroup(element));
}
else
{
ElementCompositionPreview.SetImplicitShowAnimation(element, null);
}
}
}
@ -179,15 +185,21 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations
oldCollection.AnimationsChanged -= OnAnimationsChanged;
}
if (d is UIElement element &&
e.NewValue is ImplicitAnimationSet collection)
if (d is UIElement element)
{
collection.ParentReference = new(element);
collection.AnimationsChanged -= OnAnimationsChanged;
collection.AnimationsChanged += OnAnimationsChanged;
if (e.NewValue is ImplicitAnimationSet collection)
{
collection.ParentReference = new(element);
collection.AnimationsChanged -= OnAnimationsChanged;
collection.AnimationsChanged += OnAnimationsChanged;
ElementCompositionPreview.SetIsTranslationEnabled(element, true);
ElementCompositionPreview.SetImplicitHideAnimation(element, collection.GetCompositionAnimationGroup(element));
ElementCompositionPreview.SetIsTranslationEnabled(element, true);
ElementCompositionPreview.SetImplicitHideAnimation(element, collection.GetCompositionAnimationGroup(element));
}
else
{
ElementCompositionPreview.SetImplicitHideAnimation(element, null);
}
}
}
@ -213,15 +225,21 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations
oldCollection.AnimationsChanged -= OnAnimationsChanged;
}
if (d is UIElement element &&
e.NewValue is ImplicitAnimationSet collection)
if (d is UIElement element)
{
collection.ParentReference = new(element);
collection.AnimationsChanged -= OnAnimationsChanged;
collection.AnimationsChanged += OnAnimationsChanged;
if (e.NewValue is ImplicitAnimationSet collection)
{
collection.ParentReference = new(element);
collection.AnimationsChanged -= OnAnimationsChanged;
collection.AnimationsChanged += OnAnimationsChanged;
ElementCompositionPreview.SetIsTranslationEnabled(element, true);
ElementCompositionPreview.GetElementVisual(element).ImplicitAnimations = collection.GetImplicitAnimationCollection(element);
ElementCompositionPreview.SetIsTranslationEnabled(element, true);
ElementCompositionPreview.GetElementVisual(element).ImplicitAnimations = collection.GetImplicitAnimationCollection(element);
}
else
{
ElementCompositionPreview.GetElementVisual(element).ImplicitAnimations = null;
}
}
}
}