コード例 #1
0
        /// <summary>
        ///     Translates the target element as requested by the parameters and executes the action request.
        /// </summary>
        /// <param name="target">The given element.</param>
        /// <param name="fromX">The starting x Translate transform value.</param>
        /// <param name="fromY">The starting y Translate transform value.</param>
        /// <param name="toX">The final x Translate transform value.</param>
        /// <param name="toY">The final y Translate transform value.</param>
        /// <param name="duration">How long should the transition take.</param>
        /// <param name="action">The action request to be executed later.</param>
        public static void Translate(this FrameworkElement target, double?fromX, double?fromY, double?toX, double?toY, TimeSpan duration, RequestBase action)
        {
            Storyboard board = GetAndCreateStoryboardIfNotPresent(target);

            if (fromX != null && toX != null)
            {
                (board.Children[0] as DoubleAnimation).From     = fromX;
                (board.Children[0] as DoubleAnimation).To       = toX;
                (board.Children[0] as DoubleAnimation).Duration = new Duration(duration);
            }
            if (fromY != null && toY != null)
            {
                (board.Children[1] as DoubleAnimation).From     = fromY;
                (board.Children[1] as DoubleAnimation).To       = toY;
                (board.Children[1] as DoubleAnimation).Duration = new Duration(duration);
            }

            string boardName = board.GetValue(FrameworkElement.NameProperty) as string;

            if (delayedExecution.ContainsKey(boardName))
            {
                delayedExecution.Remove(boardName);
            }
            if (action != null)
            {
                delayedExecution.Add(boardName, action);
                board.Completed += CompletedHandler;
            }

            board.Begin(target);
        }
コード例 #2
0
        internal static void ChangeScaleAndOpacity(FrameworkElement target, double?scaleFrom, double?scaleTo, double?opacityFrom, double?opacityTo, TimeSpan duration, RequestBase action)
        {
            Storyboard board = GetAndCreateStoryboardIfNotPresent(target);

            if (scaleFrom != null && scaleTo != null)
            {
                (board.Children[0] as DoubleAnimation).From     = scaleFrom;
                (board.Children[0] as DoubleAnimation).To       = scaleTo;
                (board.Children[0] as DoubleAnimation).Duration = new Duration(duration);
                (board.Children[1] as DoubleAnimation).From     = scaleFrom;
                (board.Children[1] as DoubleAnimation).To       = scaleTo;
                (board.Children[1] as DoubleAnimation).Duration = new Duration(duration);
            }
            if (opacityFrom != null && opacityTo != null)
            {
                (board.Children[2] as DoubleAnimation).From     = opacityFrom;
                (board.Children[2] as DoubleAnimation).To       = opacityTo;
                (board.Children[2] as DoubleAnimation).Duration = new Duration(duration);
            }

            string boardName = board.GetValue(FrameworkElement.NameProperty) as string;

            if (delayedExecution.ContainsKey(boardName))
            {
                delayedExecution.Remove(boardName);
            }
            if (action != null)
            {
                delayedExecution.Add(boardName, action);
                board.Completed += CompletedHandler;
            }


            board.Begin(target);
        }