Skip to content

Commit f0a9150

Browse files
committed
Merge branch 'master' of https://github.com/Tyrrrz/MaterialDesignInXamlToolkit into Tyrrrz-master
2 parents 18524dd + 2786fdd commit f0a9150

File tree

3 files changed

+135
-0
lines changed

3 files changed

+135
-0
lines changed

MaterialDesignThemes.Wpf/MaterialDesignThemes.Wpf.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@
331331
<Compile Include="SnackbarMessageQueueItem.cs" />
332332
<Compile Include="Transitions\CircleWipe.cs" />
333333
<Compile Include="IHintProxy.cs" />
334+
<Compile Include="Transitions\FadeWipe.cs" />
334335
<Compile Include="Transitions\IndexedItemOffsetMultiplierExtension.cs" />
335336
<Compile Include="Transitions\ITransitionEffect.cs" />
336337
<Compile Include="Transitions\ITransitionEffectSubject.cs" />
@@ -370,6 +371,7 @@
370371
<Compile Include="RippleAssist.cs" />
371372
<Compile Include="Ripple.cs" />
372373
<Compile Include="Transitions\IZIndexController.cs" />
374+
<Compile Include="Transitions\SlideWipe.cs" />
373375
<Compile Include="Transitions\SlideOutWipe.cs" />
374376
<Compile Include="Transitions\TransitionAssist.cs" />
375377
<Compile Include="Transitions\TransitionEffect.cs" />
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using System.Windows;
3+
using System.Windows.Media.Animation;
4+
5+
namespace MaterialDesignThemes.Wpf.Transitions
6+
{
7+
public class FadeWipe : ITransitionWipe
8+
{
9+
private readonly SineEase _sineEase = new SineEase();
10+
11+
/// <summary>
12+
/// Duration of the animation
13+
/// </summary>
14+
public TimeSpan Duration { get; set; } = TimeSpan.FromSeconds(0.5);
15+
16+
public void Wipe(TransitionerSlide fromSlide, TransitionerSlide toSlide, Point origin, IZIndexController zIndexController)
17+
{
18+
if (fromSlide == null) throw new ArgumentNullException(nameof(fromSlide));
19+
if (toSlide == null) throw new ArgumentNullException(nameof(toSlide));
20+
if (zIndexController == null) throw new ArgumentNullException(nameof(zIndexController));
21+
22+
// Set up time points
23+
var zeroKeyTime = KeyTime.FromTimeSpan(TimeSpan.Zero);
24+
var endKeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(Duration.TotalSeconds/2));
25+
26+
// Old
27+
var fromAnimation = new DoubleAnimationUsingKeyFrames();
28+
fromAnimation.KeyFrames.Add(new LinearDoubleKeyFrame(1, zeroKeyTime));
29+
fromAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(0, endKeyTime, _sineEase));
30+
31+
// New
32+
var toAnimation = new DoubleAnimationUsingKeyFrames();
33+
toAnimation.KeyFrames.Add(new LinearDoubleKeyFrame(0, zeroKeyTime));
34+
toAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(1, endKeyTime, _sineEase));
35+
36+
// Preset
37+
fromSlide.Opacity = 1;
38+
toSlide.Opacity = 0;
39+
40+
// Animate
41+
fromAnimation.Completed += (sender, args) => toSlide.BeginAnimation(UIElement.OpacityProperty, toAnimation);
42+
fromSlide.BeginAnimation(UIElement.OpacityProperty, fromAnimation);
43+
44+
zIndexController.Stack(toSlide, fromSlide);
45+
}
46+
}
47+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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

Comments
 (0)