Exemplo n.º 1
0
        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));
        }
        /// <summary>
        /// Slides an element out
        /// </summary>
        /// <param name="element">The element to animate</param>
        /// <param name="direction">The direction of the slide (this is for the reverse slide out action, so Left would slide out to left)</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>
        /// <returns></returns>
        public static async Task SlideAndFadeOutAsync(this FrameworkElement element, AnimationSlideInDirection direction, 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 to left animation
            case AnimationSlideInDirection.Left:
                sb.AddSlideToLeft(seconds, size == 0 ? element.ActualWidth : size, keepMargin: keepMargin);
                break;

            // Add slide to right animation
            case AnimationSlideInDirection.Right:
                sb.AddSlideToRight(seconds, size == 0 ? element.ActualWidth : size, keepMargin: keepMargin);
                break;

            // Add slide to top animation
            case AnimationSlideInDirection.Top:
                sb.AddSlideToTop(seconds, size == 0 ? element.ActualHeight : size, keepMargin: keepMargin);
                break;

            // Add slide to bottom animation
            case AnimationSlideInDirection.Bottom:
                sb.AddSlideToBottom(seconds, size == 0 ? element.ActualHeight : size, keepMargin: keepMargin);
                break;
            }

            // Add fade in animation
            if (fade)
            {
                sb.AddFadeOut(seconds);
            }

            // Start animating
            sb.Begin(element);

            // Make page visible only if we are animating
            if (seconds != 0)
            {
                element.Visibility = Visibility.Visible;
            }

            // Wait for it to finish
            await Task.Delay((int)(seconds * 1000));

            // Make element invisible
            if (element.Opacity == 0)
            {
                element.Visibility = Visibility.Hidden;
            }
        }
        /// <summary>
        /// Slides and fades an element out
        /// </summary>
        /// <param name="element">The element to animate</param>
        /// <param name="direction">The direction of the slide (this is for the reverse slide out action, so Left would slide out to left)</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>
        /// <returns></returns>
        public static async Task SlideAndFadeOutAsync(this FrameworkElement element, AnimationSlideInDirection direction, float seconds = 0.3f, bool keepMargin = true, int size = 0)
        {
            // Create the storyboard
            var sb = new Storyboard();

            // Slide in the correct direction
            switch (direction)
            {
            // Add slide to left animation
            case AnimationSlideInDirection.Left:
                sb.AddSlideToLeft(seconds, size == 0 ? element.ActualWidth : size, keepMargin: keepMargin);
                break;

            // Add slide to right animation
            case AnimationSlideInDirection.Right:
                sb.AddSlideToRight(seconds, size == 0 ? element.ActualWidth : size, keepMargin: keepMargin);
                break;

            // Add slide to top animation
            case AnimationSlideInDirection.Top:
                sb.AddSlideToTop(seconds, size == 0 ? element.ActualHeight : size, keepMargin: keepMargin);
                break;

            // Add slide to bottom animation
            case AnimationSlideInDirection.Bottom:
                sb.AddSlideToBottom(seconds, size == 0 ? element.ActualHeight : size, keepMargin: keepMargin);
                break;
            }

            // Add fade out animation
            sb.AddFadeOut(seconds);

            // Start animating
            sb.Begin(element);

            // Make page visible only if we are animating
            if (seconds != 0)
            {
                element.Visibility = Visibility.Visible;
            }

            // Wait for it to finish
            // For some freaking reson this is not always accurate, sometimes this delay takes few ms less than it shoud and therefore
            // the opacity check fails causing bugs
            await Task.Delay((int)(seconds * 1100));

            // Make element invisible
            if (element.Opacity == 0)
            {
                element.Visibility = Visibility.Hidden;
            }
        }
        /// <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));
        }
Exemplo n.º 5
0
        public static async Task SlideAndFadeOutAsync(this FrameworkElement element, AnimationSlideInDirection direction, float seconds = 0.3f, bool keepMargin = true, int size = 0)
        {
            var sb = new Storyboard();


            switch (direction)
            {
            case AnimationSlideInDirection.Left:
                sb.AddSlideToLeft(seconds, size == 0 ? element.ActualWidth : size, keepMargin: keepMargin);
                break;

            case AnimationSlideInDirection.Right:
                sb.AddSlideToRight(seconds, size == 0 ? element.ActualWidth : size, keepMargin: keepMargin);
                break;

            case AnimationSlideInDirection.Top:
                sb.AddSlideToTop(seconds, size == 0 ? element.ActualHeight : size, keepMargin: keepMargin);
                break;

            case AnimationSlideInDirection.Bottom:
                sb.AddSlideToBottom(seconds, size == 0 ? element.ActualHeight : size, keepMargin: keepMargin);
                break;
            }


            sb.AddFadeOut(seconds);


            sb.Begin(element);


            if (seconds != 0)
            {
                element.Visibility = Visibility.Visible;
            }


            await Task.Delay((int)(seconds * 1000));

            //애니메이션만 보여주고 결론적으로 화면에서 안보이게 함
            element.Visibility = Visibility.Hidden;
        }
        /// <summary>
        /// Slides an element out
        /// </summary>
        /// <param name="element">The element to animate</param>
        /// <param name="direction">The direction of the slide (this's for the reverse slide out action, so left would slide out to left</param>
        /// <param name="seconds">The time the animate 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>
        /// <returns></returns>
        public static async Task SlideAndFadeOutAsync(this FrameworkElement element, AnimationSlideInDirection direction, float seconds = 0.3f, bool keepMargin = true, int size = 0)
        {
            var sb = new Storyboard();

            switch (direction)
            {
            case AnimationSlideInDirection.Left:
                sb.AddSlideToLeft(seconds, size == 0 ? element.ActualWidth : size, keepMargin: keepMargin);
                break;

            case AnimationSlideInDirection.Right:
                sb.AddSlideToRight(seconds, size == 0 ? element.ActualWidth : size, keepMargin: keepMargin);
                break;

            case AnimationSlideInDirection.Top:
                sb.AddSlideToTop(seconds, size == 0 ? element.ActualHeight : size, keepMargin: keepMargin);
                break;

            case AnimationSlideInDirection.Bottom:
                sb.AddSlideToBottom(seconds, size == 0 ? element.ActualHeight : size, keepMargin: keepMargin);
                break;
            }

            // Add fade in animation
            sb.AddFadeOut(seconds);

            // Start animating
            sb.Begin(element);;

            // Make page visible only we are animating or its first load
            if (seconds != 0)
            {
                element.Visibility = Visibility.Visible;
            }

            // Wait for it to finish
            await Task.Delay((int)(seconds * 1000));

            // Make element invisible
            element.Visibility = Visibility.Hidden;
        }