-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimationHelper.cs
More file actions
66 lines (54 loc) · 2.58 KB
/
Copy pathAnimationHelper.cs
File metadata and controls
66 lines (54 loc) · 2.58 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
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
namespace VocabCoach;
/// <summary>Zentrale Animationen, die in mehreren Views wiederverwendet werden.</summary>
public static class AnimationHelper
{
/// <summary>Shrink + Fade-In (für Lösch-Animation im Dashboard, 250ms).</summary>
public static async Task AnimateDeleteAsync(FrameworkElement? element)
{
if (element == null)
{
await Task.Delay(150);
return;
}
var tgg = element.RenderTransform as TransformGroup;
if (tgg == null)
{
tgg = new TransformGroup();
element.RenderTransform = tgg;
}
var scale = tgg.Children.OfType<ScaleTransform>().FirstOrDefault();
if (scale == null)
{
scale = new ScaleTransform(1, 1);
tgg.Children.Add(scale);
}
element.RenderTransformOrigin = new Point(0.5, 0.5);
var dur = new Duration(TimeSpan.FromMilliseconds(250));
var ease = new CubicEase { EasingMode = EasingMode.EaseIn };
scale.BeginAnimation(ScaleTransform.ScaleXProperty, new DoubleAnimation(0.8, dur) { EasingFunction = ease });
scale.BeginAnimation(ScaleTransform.ScaleYProperty, new DoubleAnimation(0.8, dur) { EasingFunction = ease });
element.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation(0, dur) { EasingFunction = ease });
await Task.Delay(250);
}
/// <summary>Shrink + Fade-Out (für Vokabel-Entfernung im Import, 350ms).</summary>
public static void AnimateRemove(FrameworkElement element)
{
var tgg = element.RenderTransform as TransformGroup ?? new TransformGroup();
if (!tgg.Children.OfType<ScaleTransform>().Any())
tgg.Children.Add(new ScaleTransform(1, 1));
var scale = tgg.Children.OfType<ScaleTransform>().First();
element.RenderTransformOrigin = new Point(0.5, 0.5);
element.RenderTransform = tgg;
var ease = new CubicEase { EasingMode = EasingMode.EaseOut };
scale.BeginAnimation(ScaleTransform.ScaleXProperty, new DoubleAnimation(1, 0.6, TimeSpan.FromMilliseconds(350)) { EasingFunction = ease });
scale.BeginAnimation(ScaleTransform.ScaleYProperty, new DoubleAnimation(1, 0.6, TimeSpan.FromMilliseconds(350)) { EasingFunction = ease });
element.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation(1, 0, TimeSpan.FromMilliseconds(350)) { EasingFunction = ease });
}
}