forked from CommunityToolkit/Windows
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStartAnimationAction.cs
More file actions
79 lines (70 loc) · 2.6 KB
/
StartAnimationAction.cs
File metadata and controls
79 lines (70 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.Xaml.Interactivity;
using CommunityToolkit.WinUI.Animations;
namespace CommunityToolkit.WinUI.Behaviors;
/// <summary>
/// An <see cref="IAction"/> implementation that can trigger a target <see cref="AnimationSet"/> instance.
/// </summary>
public sealed partial class StartAnimationAction : DependencyObject, IAction
{
/// <summary>
/// Gets or sets the linked <see cref="AnimationSet"/> instance to invoke.
/// </summary>
public AnimationSet Animation
{
get => (AnimationSet)GetValue(AnimationProperty);
set => SetValue(AnimationProperty, value);
}
/// <summary>
/// Identifies the <seealso cref="Animation"/> dependency property.
/// </summary>
public static readonly DependencyProperty AnimationProperty = DependencyProperty.Register(
nameof(Animation),
typeof(AnimationSet),
typeof(StartAnimationAction),
new PropertyMetadata(null));
/// <summary>
/// Gets or sets the object to start the specified animation on. If not specified, will use the current object the parent animation is running on.
/// </summary>
public UIElement TargetObject
{
get => (UIElement)GetValue(TargetObjectProperty);
set => SetValue(TargetObjectProperty, value);
}
/// <summary>
/// Identifies the <seealso cref="TargetObject"/> dependency property.
/// </summary>
public static readonly DependencyProperty TargetObjectProperty = DependencyProperty.Register(
nameof(TargetObject),
typeof(UIElement),
typeof(StartAnimationAction),
new PropertyMetadata(null));
/// <inheritdoc/>
public object Execute(object sender, object parameter)
{
if (Animation is null)
{
ThrowArgumentNullException();
}
UIElement? parent = null;
if (Animation is not null)
{
if (TargetObject is not null)
{
Animation.Start(TargetObject);
}
else if (Animation.ParentReference?.TryGetTarget(out parent) == true) //// TODO: Tidy... apply same pattern to Activities?
{
Animation.Start(parent!);
}
else
{
Animation.Start(sender as UIElement);
}
}
return null!;
static void ThrowArgumentNullException() => throw new ArgumentNullException(nameof(Animation));
}
}