Skip to content

Commit 2786fdd

Browse files
committed
Add FadeWipe
1 parent e4c5299 commit 2786fdd

File tree

3 files changed

+51
-27
lines changed

3 files changed

+51
-27
lines changed

MaterialDesignThemes.Wpf/MaterialDesignThemes.Wpf.csproj

Lines changed: 1 addition & 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" />
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+
}

MaterialDesignThemes.Wpf/Transitions/SlideWipe.cs

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,52 +32,28 @@ public void Wipe(TransitionerSlide fromSlide, TransitionerSlide toSlide, Point o
3232
var endKeyTime = KeyTime.FromTimeSpan(Duration);
3333

3434
// Set up coordinates
35-
double fromStartX, fromEndX, toStartX, toEndX;
36-
double fromStartY, fromEndY, toStartY, toEndY;
35+
double fromStartX = 0, fromEndX = 0, toStartX = 0, toEndX = 0;
36+
double fromStartY = 0, fromEndY = 0, toStartY = 0, toEndY = 0;
3737

3838
if (Direction == SlideDirection.Left)
3939
{
40-
fromStartX = 0;
41-
fromStartY = 0;
4240
fromEndX = -fromSlide.ActualWidth;
43-
fromEndY = 0;
4441
toStartX = toSlide.ActualWidth;
45-
toStartY = 0;
46-
toEndX = 0;
47-
toEndY = 0;
4842
}
4943
else if (Direction == SlideDirection.Right)
5044
{
51-
fromStartX = 0;
52-
fromStartY = 0;
5345
fromEndX = fromSlide.ActualWidth;
54-
fromEndY = 0;
5546
toStartX = -toSlide.ActualWidth;
56-
toStartY = 0;
57-
toEndX = 0;
58-
toEndY = 0;
5947
}
6048
else if (Direction == SlideDirection.Up)
6149
{
62-
fromStartX = 0;
63-
fromStartY = 0;
64-
fromEndX = 0;
6550
fromEndY = -fromSlide.ActualHeight;
66-
toStartX = 0;
6751
toStartY = toSlide.ActualHeight;
68-
toEndX = 0;
69-
toEndY = 0;
7052
}
71-
else // if (Direction == SlideDirection.Down)
53+
else if (Direction == SlideDirection.Down)
7254
{
73-
fromStartX = 0;
74-
fromStartY = 0;
75-
fromEndX = 0;
7655
fromEndY = fromSlide.ActualHeight;
77-
toStartX = 0;
7856
toStartY = -toSlide.ActualHeight;
79-
toEndX = 0;
80-
toEndY = 0;
8157
}
8258

8359
// Old

0 commit comments

Comments
 (0)