コード例 #1
0
        /// <summary>
        /// Add a slide and fade in 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 SlideAndFadeInFromRightAsync(
            this System.Windows.Controls.Page page,
            float seconds)
        {
            // Create the storyboard
            var storyBoard = new Storyboard();

            // Add slide from right animation
            storyBoard.AddSlideFromRight(seconds, page.WindowWidth);
            // Add slide fade In
            storyBoard.AddSlideFadeIn(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 in 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="width">
        ///     The animation width to animate to. If not specified the
        ///     elements width is used
        /// </param>
        /// <returns></returns>
        public static async Task SlideAndFadeInFromLeftAsync(
            this FrameworkElement element,
            float seconds   = 0.3f,
            bool keepMargin = true,
            int width       = 0)
        {
            // Create the storyboard
            var storyBoard = new Storyboard();

            // Add slide from right animation
            storyBoard.AddSlideFromLeft(seconds, width == 0 ? element.ActualWidth : width,
                                        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));
        }