Skip to content

Commit 4f35471

Browse files
committed
Added StopAnimationAction
1 parent 608b308 commit 4f35471

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Microsoft.Toolkit.Diagnostics;
6+
using Microsoft.Toolkit.Uwp.UI.Animations;
7+
using Microsoft.Xaml.Interactivity;
8+
using Windows.UI.Xaml;
9+
10+
namespace Microsoft.Toolkit.Uwp.UI.Behaviors
11+
{
12+
/// <summary>
13+
/// An <see cref="IAction"/> implementation that can stop a target <see cref="AnimationSet"/> instance.
14+
/// </summary>
15+
public sealed class StopAnimationAction : DependencyObject, IAction
16+
{
17+
/// <summary>
18+
/// Gets or sets the linked <see cref="AnimationSet"/> instance to stop.
19+
/// </summary>
20+
public AnimationSet Animation
21+
{
22+
get => (AnimationSet)GetValue(AnimationProperty);
23+
set => SetValue(AnimationProperty, value);
24+
}
25+
26+
/// <summary>
27+
/// Identifies the <seealso cref="Animation"/> dependency property.
28+
/// </summary>
29+
public static readonly DependencyProperty AnimationProperty = DependencyProperty.Register(
30+
nameof(Animation),
31+
typeof(AnimationSet),
32+
typeof(StartAnimationAction),
33+
new PropertyMetadata(null));
34+
35+
/// <summary>
36+
/// Gets or sets the object to stop the specified animation on. If not specified, will use the current object the parent animation is running on.
37+
/// </summary>
38+
public UIElement TargetObject
39+
{
40+
get => (UIElement)GetValue(TargetObjectProperty);
41+
set => SetValue(TargetObjectProperty, value);
42+
}
43+
44+
/// <summary>
45+
/// Identifies the <seealso cref="TargetObject"/> dependency property.
46+
/// </summary>
47+
public static readonly DependencyProperty TargetObjectProperty = DependencyProperty.Register(
48+
nameof(TargetObject),
49+
typeof(UIElement),
50+
typeof(StartAnimationActivity),
51+
new PropertyMetadata(null));
52+
53+
/// <inheritdoc/>
54+
public object Execute(object sender, object parameter)
55+
{
56+
Guard.IsNotNull(Animation, nameof(Animation));
57+
58+
if (TargetObject is not null)
59+
{
60+
Animation.Stop(TargetObject);
61+
}
62+
else
63+
{
64+
Animation.Stop();
65+
}
66+
67+
return null!;
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)