-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAnimation.cs
More file actions
181 lines (149 loc) · 7.12 KB
/
Copy pathAnimation.cs
File metadata and controls
181 lines (149 loc) · 7.12 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
using System;
using System.Net;
using System.Windows;
using System.Windows.Input;
using System.Reflection;
using Windows.UI.Xaml.Media.Animation;
using Windows.UI.Xaml;
using Windows.Foundation;
namespace ControlLibrary
{
/// <summary>
/// Class defining animations
/// </summary>
internal class Animation
{
/// <summary>
/// Creates an animation on the drop target to show "hover" effect when hovering in
/// </summary>
/// <param name="objectToBeAnimated"></param>
/// <returns></returns>
internal static Storyboard CreateDropTargetHoverIn(DependencyObject objectToBeAnimated)
{
Storyboard sb = new Storyboard();
DoubleAnimationUsingKeyFrames animOpacity = new DoubleAnimationUsingKeyFrames();
animOpacity.BeginTime = new TimeSpan(0);
animOpacity.KeyFrames.Add(getSplineDoubleKeyFrame(0.0, 0));
animOpacity.KeyFrames.Add(getSplineDoubleKeyFrame(0.2, 1));
sb.Children.Add(animOpacity);
Storyboard.SetTarget(animOpacity, objectToBeAnimated);
Storyboard.SetTargetProperty(animOpacity, "(UIElement.Opacity)");
return sb;
}
/// <summary>
/// Creates an animation on the drop target to show "hover" effect when hovering in
/// </summary>
/// <param name="objectToBeAnimated"></param>
/// <returns></returns>
internal static Storyboard CreateDropTargetHoverOut(DependencyObject objectToBeAnimated)
{
Storyboard sb = new Storyboard();
DoubleAnimationUsingKeyFrames animOpacity = new DoubleAnimationUsingKeyFrames();
animOpacity.BeginTime = new TimeSpan(0);
animOpacity.KeyFrames.Add(getSplineDoubleKeyFrame(0.0, 1));
animOpacity.KeyFrames.Add(getSplineDoubleKeyFrame(0.2, 0));
sb.Children.Add(animOpacity);
Storyboard.SetTarget(animOpacity, objectToBeAnimated);
Storyboard.SetTargetProperty(animOpacity, "(UIElement.Opacity)");
return sb;
}
/// <summary>
/// Animation to return a dragged element to its original position
/// </summary>
/// <param name="objectToBeAnimated"></param>
/// <param name="CurrentPosition"></param>
/// <param name="FinalPosition"></param>
/// <param name="duration"></param>
/// <param name="easingfunction"></param>
/// <returns></returns>
internal static Storyboard ReturnDragToOriginalPosition(DependencyObject objectToBeAnimated,
Point CurrentPosition, Point FinalPosition, double duration, EasingFunctionBase easingfunction)
{
if (easingfunction == null)
{
Storyboard sb = new Storyboard();
DoubleAnimationUsingKeyFrames animTop = new DoubleAnimationUsingKeyFrames();
DoubleAnimationUsingKeyFrames animLeft = new DoubleAnimationUsingKeyFrames();
animTop.BeginTime = new TimeSpan(0);
animTop.KeyFrames.Add(getSplineDoubleKeyFrame(0.0, CurrentPosition.Y));
animTop.KeyFrames.Add(getSplineDoubleKeyFrame(duration, FinalPosition.Y));
sb.Children.Add(animTop);
Storyboard.SetTarget(animTop, objectToBeAnimated);
Storyboard.SetTargetProperty(animTop, "(Canvas.Top)");
animLeft.BeginTime = new TimeSpan(0);
animLeft.KeyFrames.Add(getSplineDoubleKeyFrame(0.0, CurrentPosition.X));
animLeft.KeyFrames.Add(getSplineDoubleKeyFrame(duration, FinalPosition.X));
sb.Children.Add(animLeft);
Storyboard.SetTarget(animLeft, objectToBeAnimated);
Storyboard.SetTargetProperty(animLeft, "(Canvas.Left)");
return sb;
}
else
{
Storyboard sb = new Storyboard();
DoubleAnimationUsingKeyFrames animTop = new DoubleAnimationUsingKeyFrames();
DoubleAnimationUsingKeyFrames animLeft = new DoubleAnimationUsingKeyFrames();
animTop.BeginTime = new TimeSpan(0);
animTop.KeyFrames.Add(getEasingDoubleKeyFrame(0.0, CurrentPosition.Y, easingfunction));
animTop.KeyFrames.Add(getEasingDoubleKeyFrame(duration, FinalPosition.Y, easingfunction));
sb.Children.Add(animTop);
Storyboard.SetTarget(animTop, objectToBeAnimated);
Storyboard.SetTargetProperty(animTop, "(Canvas.Top)");
animLeft.BeginTime = new TimeSpan(0);
animLeft.KeyFrames.Add(getEasingDoubleKeyFrame(0.0, CurrentPosition.X, easingfunction));
animLeft.KeyFrames.Add(getEasingDoubleKeyFrame(duration, FinalPosition.X, easingfunction));
sb.Children.Add(animLeft);
Storyboard.SetTarget(animLeft, objectToBeAnimated);
Storyboard.SetTargetProperty(animLeft, "(Canvas.Left)");
return sb;
}
}
/// <summary>
/// Creates an animation on the drop target to show "hover" effect when hovering in
/// </summary>
/// <param name="objectToBeAnimated"></param>
/// <returns></returns>
internal static Storyboard CreateDropTargetHoverOutFromAnyAnimationPosition(DependencyObject objectToBeAnimated)
{
Storyboard sb = new Storyboard();
DoubleAnimationUsingKeyFrames animOpacity = new DoubleAnimationUsingKeyFrames();
animOpacity.BeginTime = new TimeSpan(0);
// animOpacity.KeyFrames.Add(getSplineDoubleKeyFrame(0.0, 1));
animOpacity.KeyFrames.Add(getSplineDoubleKeyFrame(0.2, 0));
sb.Children.Add(animOpacity);
Storyboard.SetTarget(animOpacity, objectToBeAnimated);
Storyboard.SetTargetProperty(animOpacity, "(UIElement.Opacity)");
return sb;
}
/// <summary>
/// Create SplineDoubleKeyFrame, based on seconds for duration and value to animate to
/// </summary>
/// <param name="seconds"></param>
/// <param name="value"></param>
/// <returns></returns>
private static SplineDoubleKeyFrame getSplineDoubleKeyFrame(double seconds, double value)
{
return new SplineDoubleKeyFrame()
{
KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(seconds)),
Value = value
};
}
/// <summary>
/// Create EasingDoubleKeyFrame, based on seconds, duration and easing function
/// </summary>
/// <param name="seconds"></param>
/// <param name="value"></param>
/// <param name="easingfunction"></param>
/// <returns></returns>
private static EasingDoubleKeyFrame getEasingDoubleKeyFrame(double seconds, double value, EasingFunctionBase easingfunction)
{
return new EasingDoubleKeyFrame()
{
KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(seconds)),
Value = value,
EasingFunction = easingfunction
};
}
}
}