Skip to content

Commit 7105101

Browse files
committed
Minor code tweaks to parent references for implicit sets
1 parent d45c8ae commit 7105101

File tree

2 files changed

+10
-30
lines changed

2 files changed

+10
-30
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ static void OnAnimationsChanged(object sender, EventArgs e)
136136

137137
if (collection.ParentReference!.TryGetTarget(out UIElement element))
138138
{
139-
ElementCompositionPreview.SetImplicitShowAnimation(element, collection.GetCompositionAnimationGroup());
139+
ElementCompositionPreview.SetImplicitShowAnimation(element, collection.GetCompositionAnimationGroup(element));
140140
}
141141
}
142142

@@ -153,7 +153,7 @@ static void OnAnimationsChanged(object sender, EventArgs e)
153153
collection.AnimationsChanged += OnAnimationsChanged;
154154

155155
ElementCompositionPreview.SetIsTranslationEnabled(element, true);
156-
ElementCompositionPreview.SetImplicitShowAnimation(element, collection.GetCompositionAnimationGroup());
156+
ElementCompositionPreview.SetImplicitShowAnimation(element, collection.GetCompositionAnimationGroup(element));
157157
}
158158
}
159159

@@ -170,7 +170,7 @@ static void OnAnimationsChanged(object sender, EventArgs e)
170170

171171
if (collection.ParentReference!.TryGetTarget(out UIElement element))
172172
{
173-
ElementCompositionPreview.SetImplicitHideAnimation(element, collection.GetCompositionAnimationGroup());
173+
ElementCompositionPreview.SetImplicitHideAnimation(element, collection.GetCompositionAnimationGroup(element));
174174
}
175175
}
176176

@@ -187,7 +187,7 @@ static void OnAnimationsChanged(object sender, EventArgs e)
187187
collection.AnimationsChanged += OnAnimationsChanged;
188188

189189
ElementCompositionPreview.SetIsTranslationEnabled(element, true);
190-
ElementCompositionPreview.SetImplicitHideAnimation(element, collection.GetCompositionAnimationGroup());
190+
ElementCompositionPreview.SetImplicitHideAnimation(element, collection.GetCompositionAnimationGroup(element));
191191
}
192192
}
193193

@@ -204,7 +204,7 @@ static void OnAnimationsChanged(object sender, EventArgs e)
204204

205205
if (collection.ParentReference!.TryGetTarget(out UIElement element))
206206
{
207-
ElementCompositionPreview.GetElementVisual(element).ImplicitAnimations = collection.GetImplicitAnimationCollection();
207+
ElementCompositionPreview.GetElementVisual(element).ImplicitAnimations = collection.GetImplicitAnimationCollection(element);
208208
}
209209
}
210210

@@ -221,7 +221,7 @@ static void OnAnimationsChanged(object sender, EventArgs e)
221221
collection.AnimationsChanged += OnAnimationsChanged;
222222

223223
ElementCompositionPreview.SetIsTranslationEnabled(element, true);
224-
ElementCompositionPreview.GetElementVisual(element).ImplicitAnimations = collection.GetImplicitAnimationCollection();
224+
ElementCompositionPreview.GetElementVisual(element).ImplicitAnimations = collection.GetImplicitAnimationCollection(element);
225225
}
226226
}
227227
}

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

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ private void RaiseAnimationsChanged(object sender, EventArgs e)
9090
/// Creates a <see cref="CompositionAnimationGroup"/> for the current collection.
9191
/// This can be used to be assigned to show/hide implicit composition animations.
9292
/// </summary>
93+
/// <param name="parent">The target <see cref="UIElement"/> to which the animations are being applied to.</param>
9394
/// <returns>The <see cref="CompositionAnimationGroup"/> instance to use.</returns>
9495
[Pure]
95-
internal CompositionAnimationGroup GetCompositionAnimationGroup()
96+
internal CompositionAnimationGroup GetCompositionAnimationGroup(UIElement parent)
9697
{
97-
UIElement parent = GetParent();
9898
Compositor compositor = ElementCompositionPreview.GetElementVisual(parent).Compositor;
9999
CompositionAnimationGroup animations = compositor.CreateAnimationGroup();
100100

@@ -110,11 +110,11 @@ internal CompositionAnimationGroup GetCompositionAnimationGroup()
110110
/// Creates an <see cref="ImplicitAnimationCollection"/> for the current collection.
111111
/// This can be used to be assigned to implicit composition animations.
112112
/// </summary>
113+
/// <param name="parent">The target <see cref="UIElement"/> to which the animations are being applied to.</param>
113114
/// <returns>The <see cref="ImplicitAnimationCollection"/> instance to use.</returns>
114115
[Pure]
115-
internal ImplicitAnimationCollection GetImplicitAnimationCollection()
116+
internal ImplicitAnimationCollection GetImplicitAnimationCollection(UIElement parent)
116117
{
117-
UIElement parent = GetParent();
118118
Compositor compositor = ElementCompositionPreview.GetElementVisual(parent).Compositor;
119119
ImplicitAnimationCollection animations = compositor.CreateImplicitAnimationCollection();
120120

@@ -134,25 +134,5 @@ internal ImplicitAnimationCollection GetImplicitAnimationCollection()
134134

135135
return animations;
136136
}
137-
138-
/// <summary>
139-
/// Gets the current parent <see cref="UIElement"/> instance.
140-
/// </summary>
141-
/// <returns>The <see cref="UIElement"/> reference from <see cref="ParentReference"/>.</returns>
142-
/// <exception cref="InvalidOperationException">Thrown if there is no parent available.</exception>
143-
[Pure]
144-
private UIElement GetParent()
145-
{
146-
UIElement? parent = null;
147-
148-
if (ParentReference?.TryGetTarget(out parent) != true)
149-
{
150-
ThrowInvalidOperationException();
151-
}
152-
153-
return parent!;
154-
155-
static void ThrowInvalidOperationException() => throw new InvalidOperationException("The current ImplicitAnimationSet object isn't bound to a parent UIElement instance.");
156-
}
157137
}
158138
}

0 commit comments

Comments
 (0)