1
+ using System ;
2
+ using System . Windows ;
3
+ using System . Windows . Media ;
4
+ using System . Windows . Media . Animation ;
5
+
6
+ namespace MaterialDesignThemes . Wpf . Transitions
7
+ {
8
+ public class SlideWipe : ITransitionWipe
9
+ {
10
+ public enum SlideDirection { Left , Right , Up , Down }
11
+
12
+ private readonly SineEase _sineEase = new SineEase ( ) ;
13
+
14
+ /// <summary>
15
+ /// Direction of the slide wipe
16
+ /// </summary>
17
+ public SlideDirection Direction { get ; set ; }
18
+
19
+ /// <summary>
20
+ /// Duration of the animation
21
+ /// </summary>
22
+ public TimeSpan Duration { get ; set ; } = TimeSpan . FromSeconds ( 0.5 ) ;
23
+
24
+ public void Wipe ( TransitionerSlide fromSlide , TransitionerSlide toSlide , Point origin , IZIndexController zIndexController )
25
+ {
26
+ if ( fromSlide == null ) throw new ArgumentNullException ( nameof ( fromSlide ) ) ;
27
+ if ( toSlide == null ) throw new ArgumentNullException ( nameof ( toSlide ) ) ;
28
+ if ( zIndexController == null ) throw new ArgumentNullException ( nameof ( zIndexController ) ) ;
29
+
30
+ // Set up time points
31
+ var zeroKeyTime = KeyTime . FromTimeSpan ( TimeSpan . Zero ) ;
32
+ var endKeyTime = KeyTime . FromTimeSpan ( Duration ) ;
33
+
34
+ // Set up coordinates
35
+ double fromStartX = 0 , fromEndX = 0 , toStartX = 0 , toEndX = 0 ;
36
+ double fromStartY = 0 , fromEndY = 0 , toStartY = 0 , toEndY = 0 ;
37
+
38
+ if ( Direction == SlideDirection . Left )
39
+ {
40
+ fromEndX = - fromSlide . ActualWidth ;
41
+ toStartX = toSlide . ActualWidth ;
42
+ }
43
+ else if ( Direction == SlideDirection . Right )
44
+ {
45
+ fromEndX = fromSlide . ActualWidth ;
46
+ toStartX = - toSlide . ActualWidth ;
47
+ }
48
+ else if ( Direction == SlideDirection . Up )
49
+ {
50
+ fromEndY = - fromSlide . ActualHeight ;
51
+ toStartY = toSlide . ActualHeight ;
52
+ }
53
+ else if ( Direction == SlideDirection . Down )
54
+ {
55
+ fromEndY = fromSlide . ActualHeight ;
56
+ toStartY = - toSlide . ActualHeight ;
57
+ }
58
+
59
+ // Old
60
+ fromSlide . RenderTransform = new TranslateTransform ( fromStartX , fromStartY ) ;
61
+ var fromXAnimation = new DoubleAnimationUsingKeyFrames ( ) ;
62
+ fromXAnimation . KeyFrames . Add ( new LinearDoubleKeyFrame ( fromStartX , zeroKeyTime ) ) ;
63
+ fromXAnimation . KeyFrames . Add ( new EasingDoubleKeyFrame ( fromEndX , endKeyTime , _sineEase ) ) ;
64
+ var fromYAnimation = new DoubleAnimationUsingKeyFrames ( ) ;
65
+ fromYAnimation . KeyFrames . Add ( new LinearDoubleKeyFrame ( fromStartY , zeroKeyTime ) ) ;
66
+ fromYAnimation . KeyFrames . Add ( new EasingDoubleKeyFrame ( fromEndY , endKeyTime , _sineEase ) ) ;
67
+
68
+ // New
69
+ toSlide . RenderTransform = new TranslateTransform ( toStartX , toStartY ) ;
70
+ var toXAnimation = new DoubleAnimationUsingKeyFrames ( ) ;
71
+ toXAnimation . KeyFrames . Add ( new LinearDoubleKeyFrame ( toStartX , zeroKeyTime ) ) ;
72
+ toXAnimation . KeyFrames . Add ( new EasingDoubleKeyFrame ( toEndX , endKeyTime , _sineEase ) ) ;
73
+ var toYAnimation = new DoubleAnimationUsingKeyFrames ( ) ;
74
+ toYAnimation . KeyFrames . Add ( new LinearDoubleKeyFrame ( toStartY , zeroKeyTime ) ) ;
75
+ toYAnimation . KeyFrames . Add ( new EasingDoubleKeyFrame ( toEndY , endKeyTime , _sineEase ) ) ;
76
+
77
+ // Animate
78
+ fromSlide . RenderTransform . BeginAnimation ( TranslateTransform . XProperty , fromXAnimation ) ;
79
+ fromSlide . RenderTransform . BeginAnimation ( TranslateTransform . YProperty , fromYAnimation ) ;
80
+ toSlide . RenderTransform . BeginAnimation ( TranslateTransform . XProperty , toXAnimation ) ;
81
+ toSlide . RenderTransform . BeginAnimation ( TranslateTransform . YProperty , toYAnimation ) ;
82
+
83
+ zIndexController . Stack ( toSlide , fromSlide ) ;
84
+ }
85
+ }
86
+ }
0 commit comments