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 SlideRightWipe : ITransitionWipe
9
+ {
10
+ private readonly SineEase _sineEase = new SineEase ( ) ;
11
+
12
+ public void Wipe ( TransitionerSlide fromSlide , TransitionerSlide toSlide , Point origin , IZIndexController zIndexController )
13
+ {
14
+ if ( fromSlide == null ) throw new ArgumentNullException ( nameof ( fromSlide ) ) ;
15
+ if ( toSlide == null ) throw new ArgumentNullException ( nameof ( toSlide ) ) ;
16
+ if ( zIndexController == null ) throw new ArgumentNullException ( nameof ( zIndexController ) ) ;
17
+
18
+ var zeroKeyTime = KeyTime . FromTimeSpan ( TimeSpan . Zero ) ;
19
+ var midishKeyTime = KeyTime . FromTimeSpan ( TimeSpan . FromMilliseconds ( 200 ) ) ;
20
+ var endKeyTime = KeyTime . FromTimeSpan ( TimeSpan . FromMilliseconds ( 400 ) ) ;
21
+
22
+ // Old
23
+ fromSlide . RenderTransform = new TranslateTransform ( 0 , 0 ) ;
24
+ var fromSlideAnimation = new DoubleAnimationUsingKeyFrames ( ) ;
25
+ fromSlideAnimation . KeyFrames . Add ( new LinearDoubleKeyFrame ( 0 , zeroKeyTime ) ) ;
26
+ fromSlideAnimation . KeyFrames . Add ( new EasingDoubleKeyFrame ( 0 , midishKeyTime ) { EasingFunction = _sineEase } ) ;
27
+ fromSlideAnimation . KeyFrames . Add ( new EasingDoubleKeyFrame ( fromSlide . ActualWidth , endKeyTime ) { EasingFunction = _sineEase } ) ;
28
+
29
+ // New
30
+ toSlide . RenderTransform = new TranslateTransform ( - toSlide . ActualWidth , 0 ) ;
31
+ var toSlideAnimation = new DoubleAnimationUsingKeyFrames ( ) ;
32
+ toSlideAnimation . KeyFrames . Add ( new LinearDoubleKeyFrame ( - toSlide . ActualWidth , zeroKeyTime ) ) ;
33
+ toSlideAnimation . KeyFrames . Add ( new EasingDoubleKeyFrame ( - toSlide . ActualWidth , midishKeyTime ) { EasingFunction = _sineEase } ) ;
34
+ toSlideAnimation . KeyFrames . Add ( new EasingDoubleKeyFrame ( 0 , endKeyTime ) { EasingFunction = _sineEase } ) ;
35
+
36
+ // Start
37
+ fromSlide . RenderTransform . BeginAnimation ( TranslateTransform . XProperty , fromSlideAnimation ) ;
38
+ toSlide . RenderTransform . BeginAnimation ( TranslateTransform . XProperty , toSlideAnimation ) ;
39
+
40
+ zIndexController . Stack ( toSlide , fromSlide ) ;
41
+ }
42
+ }
43
+ }
0 commit comments