public static async Task SlideAndFadeInAsync(this FrameworkElement element, AnimationSlideInDirection direction, bool firstLoad, float seconds = 0.3f, bool keepMargin = true, int size = 0) { var sb = new Storyboard(); switch (direction) { case AnimationSlideInDirection.Left: sb.AddSlideFromLeft(seconds, size == 0 ? element.ActualWidth : size, keepMargin: keepMargin); break; case AnimationSlideInDirection.Right: sb.AddSlideFromRight(seconds, size == 0 ? element.ActualWidth : size, keepMargin: keepMargin); break; case AnimationSlideInDirection.Top: sb.AddSlideFromTop(seconds, size == 0 ? element.ActualHeight : size, keepMargin: keepMargin); break; case AnimationSlideInDirection.Bottom: sb.AddSlideFromBottom(seconds, size == 0 ? element.ActualHeight : size, keepMargin: keepMargin); break; } sb.AddFadeIn(seconds); sb.Begin(element); if (seconds != 0 || firstLoad) { element.Visibility = Visibility.Visible; } await Task.Delay((int)(seconds * 1000)); }
public static async Task SlideAndFadeInFromBottom(this Page page, float seconds) { Storyboard sb = new Storyboard(); sb.AddSlideFromBottom(seconds, page.WindowHeight); sb.AddFadeIn(seconds); await Animate(sb, page, seconds); }
/// <summary> /// Slide and fade in from bottom. /// </summary> /// <param name="element">The element to animate.</param> /// <param name="seconds">The seconds it takes to animate.</param> /// <param name="keepMargin"> /// Optional: Wether to keep the element at the same height during animation /// </param> /// <param name="height">Optional: Pass in a height of the element to slide and fade in</param> /// <returns>The <see cref="Task"/>.</returns> public static async Task SlideAndFadeInFromBottomAsync(this FrameworkElement element, float seconds, bool keepMargin = true, int height = 0) { var sb = new Storyboard(); sb.AddSlideFromBottom(seconds, height == 0 ? element.ActualWidth : height, keepMargin: keepMargin); sb.AddFadeIn(seconds); sb.Begin(element); element.Visibility = Visibility.Visible; await Task.Delay((int)seconds * 1000); }
public static async Task SlideAndFadeFromBottom(this Page page, float seconds) { var sb = new Storyboard(); sb.AddSlideFromBottom(seconds, page.WindowHeight); sb.Begin(page); page.Visibility = Visibility.Visible; await Task.Delay((int)(seconds * 1000)); }
/// <summary> /// Adds a slide from bottom and fade in animation /// </summary> /// <param name="page">The page to add the animation to</param> /// <param name="duration">Animation length in seconds</param> /// <returns></returns> public static async Task SlideAndFadeInFromBottomAsync(this Page page, float duration) { var storyboard = new Storyboard(); storyboard.AddSlideFromBottom(duration, page.WindowHeight); storyboard.AddFadeIn(duration); storyboard.Begin(page); page.Visibility = Visibility.Visible; // Wait for the animation to finish await Task.Delay((int)duration * 1000); }
/// <summary> /// Slides in an element from below while fading it in /// </summary> /// <param name="element">The element to animate</param> /// <param name="duration">Animation length in seconds</param> /// <param name="keepMargin">Maintain the element's height while animating</param> /// <param name="animHeight">Animation height to animate to, returns the element's height if not specified</param> /// <returns></returns> public static async Task SlideAndFadeInFromBottomAsync(this FrameworkElement element, float duration = 0.3f, bool keepMargin = true, int animHeight = 0) { var storyboard = new Storyboard(); storyboard.AddSlideFromBottom(duration, animHeight == 0 ? element.ActualHeight : animHeight, keepMargin: keepMargin); storyboard.AddFadeIn(duration); storyboard.Begin(element); element.Visibility = Visibility.Visible; await Task.Delay((int)(duration * 1000)); }
public static async Task SlideAndFadeInAsync(this FrameworkElement element, EAnimationSlideInDirection direction, Boolean isFirstLoad, Double durationInSeconds = 0.3f, Boolean keepMargin = true, Int32 size = 0) { // Create the storyboard var sb = new Storyboard(); // Slide in the correct direction switch (direction) { // Add slide from left animation case EAnimationSlideInDirection.Left: sb.AddSlideFromLeft(durationInSeconds, size == 0 ? element.ActualWidth : size, keepMargin: keepMargin); break; // Add slide from right animation case EAnimationSlideInDirection.Right: sb.AddSlideFromRight(durationInSeconds, size == 0 ? element.ActualWidth : size, keepMargin: keepMargin); break; // Add slide from top animation case EAnimationSlideInDirection.Top: sb.AddSlideFromTop(durationInSeconds, size == 0 ? element.ActualHeight : size, keepMargin: keepMargin); break; // Add slide from bottom animation case EAnimationSlideInDirection.Bottom: sb.AddSlideFromBottom(durationInSeconds, size == 0 ? element.ActualHeight : size, keepMargin: keepMargin); break; default: throw new ArgumentOutOfRangeException(nameof(direction), direction, null); } // Add fade in animation sb.AddFadeIn(durationInSeconds); // Start animating sb.Begin(element); // Make page visible only if we are animating or its the first load Double tolerance = Double.Epsilon * 1.0E5; if (Math.Abs(durationInSeconds) > tolerance || isFirstLoad) { element.Visibility = Visibility.Visible; } // Wait for it to finish await Task.Delay((Int32)(durationInSeconds * 1000)); }
/// <summary> /// Slides an element in /// </summary> /// <param name="element">The element to animate</param> /// <param name="direction">The direction of the slide</param> /// <param name="seconds">The time the animation will take</param> /// <param name="keepMargin">Whether to keep the element at the same width during animation</param> /// <param name="size">The animation width/height to animate to. If not specified the elements size is used</param> /// <param name="firstLoad">Indicates if this is the first load</param> /// <returns></returns> public static async Task SlideAndFadeInAsync(this FrameworkElement element, AnimationSlideInDirection direction, bool firstLoad, float seconds = 0.3f, bool keepMargin = true, int size = 0, bool fade = true) { // Create the storyboard var sb = new Storyboard(); // Slide in the correct direction switch (direction) { // Add slide from left animation case AnimationSlideInDirection.Left: sb.AddSlideFromLeft(seconds, size == 0 ? element.ActualWidth : size, keepMargin: keepMargin); break; // Add slide from right animation case AnimationSlideInDirection.Right: sb.AddSlideFromRight(seconds, size == 0 ? element.ActualWidth : size, keepMargin: keepMargin); break; // Add slide from top animation case AnimationSlideInDirection.Top: sb.AddSlideFromTop(seconds, size == 0 ? element.ActualHeight : size, keepMargin: keepMargin); break; // Add slide from bottom animation case AnimationSlideInDirection.Bottom: sb.AddSlideFromBottom(seconds, size == 0 ? element.ActualHeight : size, keepMargin: keepMargin); break; } // Add fade in animation if (fade) { sb.AddFadeIn(seconds); } // Start animating sb.Begin(element); // Make page visible only if we are animating or its the first load if (seconds != 0 || firstLoad) { element.Visibility = Visibility.Visible; } // Wait for it to finish await Task.Delay((int)(seconds * 1000)); }
/// <summary> /// Slides an element in from the bottom /// </summary> /// <param name="element">The element to animate</param> /// <param name="seconds">The time the animation will take</param> /// <param name="keepMargin">Whether to keep the element at the same width during animation</param> /// <returns></returns> public static async Task SlideAndFadeInFromBottomAsync(this FrameworkElement element, float seconds = 0.2f, bool keepMargin = true) { // Create the storyboard var sb = new Storyboard(); // Add slide from bottom animation sb.AddSlideFromBottom(seconds, element.ActualHeight, keepMargin: keepMargin); // Add fade in animation sb.AddFadeIn(seconds); // Start animating sb.Begin(element); // Make element visible element.Visibility = Visibility.Visible; // Wait for it to finish await Task.Delay((int)seconds * 1000); }
/// <summary> /// Slides a page in from the bottom /// </summary> /// <param name="page">The page to animate</param> /// <param name="seconds">The time the animation take</param> /// <returns></returns> public static async Task SlideAndFadeInFromBottom(this Page page, float seconds) { // Create the storyboard var sb = new Storyboard(); //Add slide from right animation sb.AddSlideFromBottom(seconds, page.WindowHeight); //Add fade in animation sb.AddFadeIn(seconds); // Start animating sb.Begin(page); // Make page visible page.Visibility = Visibility.Visible; // Wait for it to finish await Task.Delay((int)(seconds * 1000)); }
/// <summary> /// Add a slide and fade out animation to the story board /// </summary> /// <param name="element"> The element that needs animation </param> /// <param name="seconds"> The animation duration </param> /// <param name="keepMargin"> /// Whether to keep the element at the same width during /// animation /// </param> /// <param name="height"> /// The animation width to animate to. If not specified the /// elements width is used /// </param> /// <returns></returns> public static async Task SlideAndFadeInFromBottomAsync( this FrameworkElement element, float seconds = 0.3f, bool keepMargin = true, int height = 0) { // Create the storyboard var storyBoard = new Storyboard(); // // Add slide to left animation storyBoard.AddSlideFromBottom(seconds, height == 0 ? element.ActualWidth : height, keepMargin: keepMargin); // Add slide fade In storyBoard.AddSlideFadeIn(seconds); storyBoard.Begin(element); // storyboard开始,以为这动画开始,那么我们将 element 显示出来 element.Visibility = Visibility.Visible; // 等待动画结束,此时,该page的线程出于stop的状态,任何操作都不允许。 await Task.Delay((int)(seconds * 1000)); }
/// <summary> /// Slide an element in from the right /// </summary> /// <param name="page">The element to animate</param> /// <param name="seconds">The time the animation will take</param> /// <param name="keepMargin">Whether to keep the element at the same height during animation</param> /// <param name="height">The animation height to animate to. If not specified the elements height is used</param> /// <returns></returns> public static async Task SlideAndFadeInFromBottomAsync(this FrameworkElement element, float seconds = 0.3f, bool keepMargin = true, int height = 0) { //Create the storyboard var sb = new Storyboard(); //Add slide from bottom animation sb.AddSlideFromBottom(seconds, height == 0 ? element.ActualHeight : height, keepMargin: keepMargin); //Add fade in animation sb.AddFadeIn(seconds); //Start animating sb.Begin(element); //Make page visible if (seconds != 0) { element.Visibility = Visibility.Visible; } await Task.Delay((int)(seconds * 1000)); }
public static async Task SlideAndFadeInAsync(this FrameworkElement element, FrameworkElementAnimations direction, bool firstLoad, float seconds = 0.3f, bool keepMargin = true, int size = 0) { var storyboard = new Storyboard(); var width = size.Equals(0) ? element.ActualWidth : size; var height = size.Equals(0) ? element.ActualHeight : size; switch (direction) { case FrameworkElementAnimations.Left: storyboard.AddSlideFromLeft(seconds, width, keepMargin: keepMargin); break; case FrameworkElementAnimations.Right: storyboard.AddSlideFromRight(seconds, width, keepMargin: keepMargin); break; case FrameworkElementAnimations.Top: storyboard.AddSlideFromTop(seconds, height, keepMargin: keepMargin); break; case FrameworkElementAnimations.Bottom: storyboard.AddSlideFromBottom(seconds, height, keepMargin: keepMargin); break; } storyboard.AddFadeIn(seconds); storyboard.Begin(element); if (seconds != 0.0f || firstLoad) { element.Visibility = Visibility.Visible; } var delay = (int)(seconds * 1000); await Task.Delay(delay); }
/// <summary> /// Slides an element in from the bottom /// </summary> /// <param name="element">The element to animate</param> /// <param name="seconds">The time the animation will take</param> /// <returns></returns> public static async Task SlideAndFadeInFromBottom(this FrameworkElement element, float seconds = 0.7f) { // Make page visible element.Visibility = Visibility.Visible; // Create the storyboard var sb = new Storyboard(); // Add slide from right animation sb.AddSlideFromBottom(seconds, element.ActualWidth); // Add fade in animation sb.AddFadeIn(seconds); // Start animating sb.Begin(element); // Make page visible element.Visibility = Visibility.Visible; // Wait for it to finish await Task.Delay((int)(seconds * 1000)); }