コード例 #1
0
        /// <summary>
        /// Add a slide and fade out animation to the story board
        /// </summary>
        /// <param name="page"> The page that needs animation </param>
        /// <param name="seconds"> The animation duration </param>
        /// <returns></returns>
        public static async Task SlideAndFadeOutToLeft(
            this System.Windows.Controls.Page page,
            float seconds)
        {
            // Create the storyboard
            var storyBoard = new Storyboard();

            // // Add slide to left animation
            storyBoard.AddSlideToLeft(seconds, page.WindowWidth);
            // Add slide fade In
            storyBoard.AddSlideFadeOut(seconds);

            storyBoard.Begin(page);
            // storyboard开始,以为这动画开始,那么我们将 page 显示出来
            page.Visibility = Visibility.Visible;

            // 等待动画结束,此时,该page的线程出于stop的状态,任何操作都不允许。
            await Task.Delay((int)(seconds * 1000));
        }
コード例 #2
0
        /// <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 SlideAndFadeOutToBottomAsync(
            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.AddSlideToBottom(seconds, height == 0 ? element.ActualWidth : height,
                                        keepMargin: keepMargin);
            // Add slide fade In
            storyBoard.AddSlideFadeOut(seconds);

            storyBoard.Begin(element);
            // storyboard开始,以为这动画开始,那么我们将 element 显示出来
            element.Visibility = Visibility.Visible;

            // 等待动画结束,此时,该page的线程出于stop的状态,任何操作都不允许。
            await Task.Delay((int)(seconds * 1000));
        }