Repository navigation
Expand file tree
/
Copy pathGridLengthAnimation.cs
More file actions
49 lines (35 loc) · 1.58 KB
/
Copy pathGridLengthAnimation.cs
File metadata and controls
49 lines (35 loc) · 1.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
using System.Windows;
using System.Windows.Media.Animation;
namespace Lychee;
public sealed class GridLengthAnimation : AnimationTimeline
{
public static readonly DependencyProperty FromProperty =
DependencyProperty.Register(nameof(From), typeof(GridLength?), typeof(GridLengthAnimation));
public static readonly DependencyProperty ToProperty =
DependencyProperty.Register(nameof(To), typeof(GridLength?), typeof(GridLengthAnimation));
public GridLength? From
{
get => (GridLength?)GetValue(FromProperty);
set => SetValue(FromProperty, value);
}
public GridLength? To
{
get => (GridLength?)GetValue(ToProperty);
set => SetValue(ToProperty, value);
}
public IEasingFunction? EasingFunction { get; set; }
public override Type TargetPropertyType => typeof(GridLength);
public override object GetCurrentValue(object defaultOriginValue, object defaultDestinationValue,
AnimationClock animationClock)
{
if (animationClock == null) return From ?? GridLength.Auto;
var fromVal = From?.Value ?? ((GridLength)defaultOriginValue).Value;
var toVal = To?.Value ?? ((GridLength)defaultDestinationValue).Value;
var progress = animationClock.CurrentProgress ?? 0;
if (EasingFunction != null) progress = EasingFunction.Ease(progress);
var value = fromVal + (toVal - fromVal) * progress;
if (value < 0) value = 0;
return new GridLength(value, GridUnitType.Pixel);
}
protected override Freezable CreateInstanceCore() => new GridLengthAnimation();
}