コード例 #1
0
        /// <summary>
        /// Triggers the disappearance of a UIElement.
        /// </summary>
        /// <param name="uiElement"></param>
        /// <param name="done"></param>
        public static void Disappear(UIElement uiElement, Action <UIElement> done)
        {
            DateTime        startTime       = DateTime.Now;
            Transition      transition      = GetDisappearance(uiElement);
            TransitionState transitionState = null;

            if (activeDisappearances.TryGetValue(uiElement, out transitionState))
            {
                transitionState.Progress = double.NaN;
                activeDisappearances.Remove(uiElement);
            }

            if (activeAppearances.TryGetValue(uiElement, out transitionState))
            {
                if (transition != null)
                {
                    startTime = startTime - TimeSpan.FromSeconds((1.0 - transitionState.Progress) * transition.Duration.TimeSpan.TotalSeconds);
                }

                transitionState.Progress = double.NaN;
                activeAppearances.Remove(uiElement);
            }

            if (transition != null)
            {
                transitionState = transition.CreateTransitionState();
                activeDisappearances.Add(uiElement, transitionState);

                transitionState.Transition = transition;
                transitionState.UIElement  = uiElement;
                transitionState.StartTime  = startTime;
                transitionState.EndTime    = transitionState.StartTime + transition.Duration.TimeSpan;
                transitionState.Done       = done;
                transitionState.Progress   = 1.0;
            }
            else
            {
                if (done != null)
                {
                    done(uiElement);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Cancels a UIElements appearance or disappearance.
        /// </summary>
        /// <param name="uiElement"></param>
        /// <param name="done"></param>
        /// <returns></returns>
        public static bool Cancel(UIElement uiElement, bool done)
        {
            Dictionary <UIElement, TransitionState> active = activeAppearances.ContainsKey(uiElement) ? activeAppearances :
                                                             activeDisappearances.ContainsKey(uiElement) ? activeDisappearances :
                                                             null;

            if (active != null)
            {
                TransitionState transitionState = active[uiElement];

                transitionState.Progress = double.NaN;

                if (done && transitionState.Done != null)
                {
                    transitionState.Done(uiElement);
                }

                active.Remove(uiElement);

                return(true);
            }

            return(false);
        }