Skip to content

Commit 497bd6b

Browse files
committed
Enabled notification updates to Implicit APIs
1 parent 713675b commit 497bd6b

File tree

2 files changed

+56
-12
lines changed

2 files changed

+56
-12
lines changed

Microsoft.Toolkit.Uwp.UI.Animations/Implicit.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using System;
56
using Windows.Foundation.Collections;
67
using Windows.UI.Xaml;
78
using Windows.UI.Xaml.Hosting;
@@ -130,7 +131,7 @@ public static void SetAnimations(UIElement element, ImplicitAnimationSet value)
130131
/// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance for the current event.</param>
131132
private static void OnShowAnimationsPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
132133
{
133-
static void OnAnimationsChanged(IObservableVector<DependencyObject> sender, IVectorChangedEventArgs args)
134+
static void OnAnimationsChanged(object sender, EventArgs e)
134135
{
135136
var collection = (ImplicitAnimationSet)sender;
136137

@@ -142,15 +143,15 @@ static void OnAnimationsChanged(IObservableVector<DependencyObject> sender, IVec
142143

143144
if (e.OldValue is ImplicitAnimationSet oldCollection)
144145
{
145-
oldCollection.VectorChanged -= OnAnimationsChanged;
146+
oldCollection.AnimationsChanged -= OnAnimationsChanged;
146147
}
147148

148149
if (d is UIElement element &&
149150
e.NewValue is ImplicitAnimationSet collection)
150151
{
151152
collection.ParentReference = new(element);
152-
collection.VectorChanged -= OnAnimationsChanged;
153-
collection.VectorChanged += OnAnimationsChanged;
153+
collection.AnimationsChanged -= OnAnimationsChanged;
154+
collection.AnimationsChanged += OnAnimationsChanged;
154155

155156
ElementCompositionPreview.SetIsTranslationEnabled(element, true);
156157
ElementCompositionPreview.SetImplicitShowAnimation(element, collection.GetCompositionAnimationGroup());
@@ -164,7 +165,7 @@ static void OnAnimationsChanged(IObservableVector<DependencyObject> sender, IVec
164165
/// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance for the current event.</param>
165166
private static void OnHideAnimationsPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
166167
{
167-
static void OnAnimationsChanged(IObservableVector<DependencyObject> sender, IVectorChangedEventArgs args)
168+
static void OnAnimationsChanged(object sender, EventArgs e)
168169
{
169170
var collection = (ImplicitAnimationSet)sender;
170171

@@ -176,15 +177,15 @@ static void OnAnimationsChanged(IObservableVector<DependencyObject> sender, IVec
176177

177178
if (e.OldValue is ImplicitAnimationSet oldCollection)
178179
{
179-
oldCollection.VectorChanged -= OnAnimationsChanged;
180+
oldCollection.AnimationsChanged -= OnAnimationsChanged;
180181
}
181182

182183
if (d is UIElement element &&
183184
e.NewValue is ImplicitAnimationSet collection)
184185
{
185186
collection.ParentReference = new(element);
186-
collection.VectorChanged -= OnAnimationsChanged;
187-
collection.VectorChanged += OnAnimationsChanged;
187+
collection.AnimationsChanged -= OnAnimationsChanged;
188+
collection.AnimationsChanged += OnAnimationsChanged;
188189

189190
ElementCompositionPreview.SetIsTranslationEnabled(element, true);
190191
ElementCompositionPreview.SetImplicitHideAnimation(element, collection.GetCompositionAnimationGroup());
@@ -198,7 +199,7 @@ static void OnAnimationsChanged(IObservableVector<DependencyObject> sender, IVec
198199
/// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance for the current event.</param>
199200
private static void OnAnimationsPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
200201
{
201-
static void OnAnimationsChanged(IObservableVector<DependencyObject> sender, IVectorChangedEventArgs args)
202+
static void OnAnimationsChanged(object sender, EventArgs e)
202203
{
203204
var collection = (ImplicitAnimationSet)sender;
204205

@@ -210,15 +211,15 @@ static void OnAnimationsChanged(IObservableVector<DependencyObject> sender, IVec
210211

211212
if (e.OldValue is ImplicitAnimationSet oldCollection)
212213
{
213-
oldCollection.VectorChanged -= OnAnimationsChanged;
214+
oldCollection.AnimationsChanged -= OnAnimationsChanged;
214215
}
215216

216217
if (d is UIElement element &&
217218
e.NewValue is ImplicitAnimationSet collection)
218219
{
219220
collection.ParentReference = new(element);
220-
collection.VectorChanged -= OnAnimationsChanged;
221-
collection.VectorChanged += OnAnimationsChanged;
221+
collection.AnimationsChanged -= OnAnimationsChanged;
222+
collection.AnimationsChanged += OnAnimationsChanged;
222223

223224
ElementCompositionPreview.SetIsTranslationEnabled(element, true);
224225
ElementCompositionPreview.GetElementVisual(element).ImplicitAnimations = collection.GetImplicitAnimationCollection();

Microsoft.Toolkit.Uwp.UI.Animations/Xaml/ImplicitAnimationSet.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
using System;
88
using System.Diagnostics.Contracts;
9+
using Windows.Foundation.Collections;
910
using Windows.UI.Composition;
1011
using Windows.UI.Xaml;
1112
using Windows.UI.Xaml.Hosting;
@@ -18,6 +19,48 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations
1819
/// </summary>
1920
public sealed class ImplicitAnimationSet : DependencyObjectCollection
2021
{
22+
/// <summary>
23+
/// Raised whenever any configuration change occurrs within the current <see cref="ImplicitAnimationSet"/> instance.
24+
/// </summary>
25+
internal event EventHandler? AnimationsChanged;
26+
27+
/// <summary>
28+
/// Initializes a new instance of the <see cref="ImplicitAnimationSet"/> class.
29+
/// </summary>
30+
public ImplicitAnimationSet()
31+
{
32+
VectorChanged += this.ImplicitAnimationSetVectorChanged;
33+
}
34+
35+
/// <summary>
36+
/// Registers <see cref="RaiseAnimationsChanged(object, EventArgs)"/> for every added animation.
37+
/// </summary>
38+
/// <param name="sender">The current vector of animations.</param>
39+
/// <param name="event">The <see cref="IVectorChangedEventArgs"/> instance for the current event.</param>
40+
private void ImplicitAnimationSetVectorChanged(IObservableVector<DependencyObject> sender, IVectorChangedEventArgs @event)
41+
{
42+
if (@event.CollectionChange == CollectionChange.ItemInserted ||
43+
@event.CollectionChange == CollectionChange.ItemChanged)
44+
{
45+
IInternalImplicitAnimation item = (IInternalImplicitAnimation)sender[(int)@event.Index];
46+
47+
item.AnimationPropertyChanged -= RaiseAnimationsChanged;
48+
item.AnimationPropertyChanged += RaiseAnimationsChanged;
49+
}
50+
51+
AnimationsChanged?.Invoke(this, EventArgs.Empty);
52+
}
53+
54+
/// <summary>
55+
/// Raisess the <see cref="AnimationsChanged"/> event.
56+
/// </summary>
57+
/// <param name="sender">The instance raising the event.</param>
58+
/// <param name="e">The empty <see cref="EventArgs"/> for the event.</param>
59+
private void RaiseAnimationsChanged(object sender, EventArgs e)
60+
{
61+
AnimationsChanged?.Invoke(this, e);
62+
}
63+
2164
/// <summary>
2265
/// Gets or sets the weak reference to the parent that owns the current implicit animation collection.
2366
/// </summary>

0 commit comments

Comments
 (0)