-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move ThemeAnimationHelper to Helper Folder
- Loading branch information
Showing
3 changed files
with
69 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 0 additions & 66 deletions
66
src/Shared/HandyControl_Shared/HandyControls/ThemeManager/ThemeAnimationHelper.cs
This file was deleted.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
src/Shared/HandyControl_Shared/Tools/Helper/ThemeAnimationHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Media.Animation; | ||
|
||
namespace HandyControl.Tools.Helper; | ||
public static class ThemeAnimationHelper | ||
{ | ||
public async static void AnimateTheme(UIElement element, SlideDirection slideDirection, double durationSeconds, double fromOpacity, double toOpacity) | ||
{ | ||
if (element != null) | ||
{ | ||
DoubleAnimation opacityAnimation = new DoubleAnimation(); | ||
opacityAnimation.From = fromOpacity; | ||
opacityAnimation.To = toOpacity; | ||
opacityAnimation.Duration = TimeSpan.FromSeconds(durationSeconds); | ||
|
||
ThicknessAnimation slideAnimation = new ThicknessAnimation(); | ||
slideAnimation.Duration = TimeSpan.FromSeconds(durationSeconds); | ||
slideAnimation.From = GetSlideFromThickness(element, slideDirection); | ||
slideAnimation.To = new Thickness(0); | ||
|
||
Storyboard storyboard = new Storyboard(); | ||
storyboard.Children.Add(opacityAnimation); | ||
storyboard.Children.Add(slideAnimation); | ||
Storyboard.SetTarget(opacityAnimation, element); | ||
Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath(UIElement.OpacityProperty)); | ||
Storyboard.SetTarget(slideAnimation, element); | ||
Storyboard.SetTargetProperty(slideAnimation, new PropertyPath(FrameworkElement.MarginProperty)); | ||
|
||
storyboard.Begin(); | ||
#if NET40 | ||
Thread.Sleep(TimeSpan.FromSeconds(durationSeconds)); | ||
#else | ||
await Task.Delay(TimeSpan.FromSeconds(durationSeconds)); // Wait for the fade out animation to finish | ||
#endif | ||
} | ||
} | ||
|
||
public enum SlideDirection | ||
{ | ||
Left, | ||
Right, | ||
Top, | ||
Bottom | ||
} | ||
|
||
private static Thickness GetSlideFromThickness(UIElement element, SlideDirection slideDirection) | ||
{ | ||
double elementWidth = element.RenderSize.Width; | ||
double elementHeight = element.RenderSize.Height; | ||
|
||
switch (slideDirection) | ||
{ | ||
case SlideDirection.Left: | ||
return new Thickness(-elementWidth, 0, elementWidth, 0); | ||
case SlideDirection.Right: | ||
return new Thickness(elementWidth, 0, -elementWidth, 0); | ||
case SlideDirection.Top: | ||
return new Thickness(0, -elementHeight, 0, elementHeight); | ||
case SlideDirection.Bottom: | ||
return new Thickness(0, elementHeight, 0, -elementHeight); | ||
default: | ||
return new Thickness(); | ||
} | ||
} | ||
|
||
} |