Skip to content

Commit 77b21d9

Browse files
committed
Merge branch 'Tyrrrz-master'
2 parents 528d245 + ce8de1f commit 77b21d9

File tree

5 files changed

+180
-0
lines changed

5 files changed

+180
-0
lines changed

MainDemo.Wpf/TransitionsDemo/TransitionsDemoHome.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
<materialDesign:TransitionerSlide.BackwardWipe>
3939
<materialDesign:CircleWipe />
4040
</materialDesign:TransitionerSlide.BackwardWipe>
41+
<materialDesign:TransitionerSlide.ForwardWipe>
42+
<materialDesign:SlideWipe Direction="Right" />
43+
</materialDesign:TransitionerSlide.ForwardWipe>
4144
<local:Slide3_Intro />
4245
</materialDesign:TransitionerSlide>
4346

MaterialDesignThemes.Wpf/MaterialDesignThemes.Wpf.csproj

Lines changed: 3 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,8 @@
370371
<Compile Include="RippleAssist.cs" />
371372
<Compile Include="Ripple.cs" />
372373
<Compile Include="Transitions\IZIndexController.cs" />
374+
<Compile Include="Transitions\SlideDirection.cs" />
375+
<Compile Include="Transitions\SlideWipe.cs" />
373376
<Compile Include="Transitions\SlideOutWipe.cs" />
374377
<Compile Include="Transitions\TransitionAssist.cs" />
375378
<Compile Include="Transitions\TransitionEffect.cs" />
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
// From
27+
var fromAnimation = new DoubleAnimationUsingKeyFrames();
28+
fromAnimation.KeyFrames.Add(new LinearDoubleKeyFrame(1, zeroKeyTime));
29+
fromAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(0, endKeyTime, _sineEase));
30+
31+
// To
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+
// Set up events
41+
toAnimation.Completed += (sender, args) =>
42+
{
43+
toSlide.BeginAnimation(UIElement.OpacityProperty, null);
44+
fromSlide.Opacity = 0;
45+
toSlide.Opacity = 1;
46+
};
47+
fromAnimation.Completed += (sender, args) =>
48+
{
49+
fromSlide.BeginAnimation(UIElement.OpacityProperty, null);
50+
fromSlide.Opacity = 0;
51+
toSlide.BeginAnimation(UIElement.OpacityProperty, toAnimation);
52+
};
53+
54+
// Animate
55+
fromSlide.BeginAnimation(UIElement.OpacityProperty, fromAnimation);
56+
zIndexController.Stack(toSlide, fromSlide);
57+
}
58+
}
59+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
namespace MaterialDesignThemes.Wpf.Transitions
2+
{
3+
public enum SlideDirection { Left, Right, Up, Down }
4+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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+
private readonly SineEase _sineEase = new SineEase();
11+
12+
/// <summary>
13+
/// Direction of the slide wipe
14+
/// </summary>
15+
public SlideDirection Direction { get; set; }
16+
17+
/// <summary>
18+
/// Duration of the animation
19+
/// </summary>
20+
public TimeSpan Duration { get; set; } = TimeSpan.FromSeconds(0.5);
21+
22+
public void Wipe(TransitionerSlide fromSlide, TransitionerSlide toSlide, Point origin, IZIndexController zIndexController)
23+
{
24+
if (fromSlide == null) throw new ArgumentNullException(nameof(fromSlide));
25+
if (toSlide == null) throw new ArgumentNullException(nameof(toSlide));
26+
if (zIndexController == null) throw new ArgumentNullException(nameof(zIndexController));
27+
28+
// Set up time points
29+
var zeroKeyTime = KeyTime.FromTimeSpan(TimeSpan.Zero);
30+
var endKeyTime = KeyTime.FromTimeSpan(Duration);
31+
32+
// Set up coordinates
33+
double fromStartX = 0, fromEndX = 0, toStartX = 0, toEndX = 0;
34+
double fromStartY = 0, fromEndY = 0, toStartY = 0, toEndY = 0;
35+
36+
if (Direction == SlideDirection.Left)
37+
{
38+
fromEndX = -fromSlide.ActualWidth;
39+
toStartX = toSlide.ActualWidth;
40+
}
41+
else if (Direction == SlideDirection.Right)
42+
{
43+
fromEndX = fromSlide.ActualWidth;
44+
toStartX = -toSlide.ActualWidth;
45+
}
46+
else if (Direction == SlideDirection.Up)
47+
{
48+
fromEndY = -fromSlide.ActualHeight;
49+
toStartY = toSlide.ActualHeight;
50+
}
51+
else if (Direction == SlideDirection.Down)
52+
{
53+
fromEndY = fromSlide.ActualHeight;
54+
toStartY = -toSlide.ActualHeight;
55+
}
56+
57+
// From
58+
var fromTransform = new TranslateTransform(fromStartX, fromStartY);
59+
fromSlide.RenderTransform = fromTransform;
60+
var fromXAnimation = new DoubleAnimationUsingKeyFrames();
61+
fromXAnimation.KeyFrames.Add(new LinearDoubleKeyFrame(fromStartX, zeroKeyTime));
62+
fromXAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(fromEndX, endKeyTime, _sineEase));
63+
var fromYAnimation = new DoubleAnimationUsingKeyFrames();
64+
fromYAnimation.KeyFrames.Add(new LinearDoubleKeyFrame(fromStartY, zeroKeyTime));
65+
fromYAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(fromEndY, endKeyTime, _sineEase));
66+
67+
// To
68+
var toTransform = new TranslateTransform(toStartX, toStartY);
69+
toSlide.RenderTransform = toTransform;
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+
// Set up events
78+
fromXAnimation.Completed += (sender, args) =>
79+
{
80+
fromTransform.BeginAnimation(TranslateTransform.XProperty, null);
81+
fromTransform.X = fromEndX;
82+
fromSlide.RenderTransform = null;
83+
};
84+
fromYAnimation.Completed += (sender, args) =>
85+
{
86+
fromTransform.BeginAnimation(TranslateTransform.YProperty, null);
87+
fromTransform.Y = fromEndY;
88+
fromSlide.RenderTransform = null;
89+
};
90+
toXAnimation.Completed += (sender, args) =>
91+
{
92+
toTransform.BeginAnimation(TranslateTransform.XProperty, null);
93+
toTransform.X = toEndX;
94+
toSlide.RenderTransform = null;
95+
};
96+
toYAnimation.Completed += (sender, args) =>
97+
{
98+
toTransform.BeginAnimation(TranslateTransform.YProperty, null);
99+
toTransform.Y = toEndY;
100+
toSlide.RenderTransform = null;
101+
};
102+
103+
// Animate
104+
fromTransform.BeginAnimation(TranslateTransform.XProperty, fromXAnimation);
105+
fromTransform.BeginAnimation(TranslateTransform.YProperty, fromYAnimation);
106+
toTransform.BeginAnimation(TranslateTransform.XProperty, toXAnimation);
107+
toTransform.BeginAnimation(TranslateTransform.YProperty, toYAnimation);
108+
zIndexController.Stack(toSlide, fromSlide);
109+
}
110+
}
111+
}

0 commit comments

Comments
 (0)