-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnimations.cs
67 lines (55 loc) · 2.28 KB
/
Animations.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;
namespace ReportManager
{
class Animations
{
public static void AnimateMenuWidth(Grid grid, double width, bool isRelative = false)
{
//---------------------------------------------------
// Settings
//---------------------------------------------------
TimeSpan duration = TimeSpan.FromSeconds(.2);
double newWidth = isRelative ? grid.Width - width : width;
_ = grid.Dispatcher.BeginInvoke(new Action(() =>
{
Storyboard storyboard = new Storyboard();
//---------------------------------------------------
// Animate Height
//---------------------------------------------------
DoubleAnimation widthAnimation = new DoubleAnimation()
{
Duration = new Duration(duration),
From = grid.ActualWidth,
To = newWidth
};
Storyboard.SetTarget(widthAnimation, grid);
Storyboard.SetTargetProperty(widthAnimation, new PropertyPath(Grid.WidthProperty));
storyboard.Children.Add(widthAnimation);
//---------------------------------------------------
// Play
//---------------------------------------------------
grid.BeginStoryboard(storyboard, HandoffBehavior.SnapshotAndReplace, false);
}), null);
}
public static void AnimateMargin(Grid grid, int newMargin)
{
var sb = new Storyboard();
var ta = new ThicknessAnimation();
ta.BeginTime = new TimeSpan(0);
Storyboard.SetTargetProperty(ta, new PropertyPath(Grid.MarginProperty));
var actualMargin = grid.Margin.Left;
ta.From = new Thickness(actualMargin, 50, 0, 0);
ta.To = new Thickness(newMargin, 50, 0, 0);
ta.Duration = new Duration(TimeSpan.FromSeconds(.2));
sb.Children.Add(ta);
sb.Begin(grid);
}
}
}