Пример #1
0
        /// <summary>
        ///     Realiza la navegación al Panel anterior.
        /// </summary>
        /// <returns>Devuelve la instancia del Panel anterior.</returns>
        public UserControl PreviousPanel()
        {
            // Revisar si es necesaio un Invoke.
            if (InvokeRequired)
            {
                return((UserControl)Invoke(
                           new Func <UserControl>(() => PreviousPanel())
                           ));
            }

            if (m_currentPanelNode == null || m_currentPanelNode.Value == null)
            {
                throw new InvalidOperationException("There is exactly NO f*****g panels in history.");
            }

            if (m_currentPanelNode.Previous == null || m_currentPanelNode.Previous.Value == null)
            {
                throw new InvalidOperationException("There is no panel to go back to.");
            }

            UserControl currentPanel  = m_currentPanelNode.Value;
            UserControl previousPanel = m_currentPanelNode.Previous.Value;

            m_currentPanelNode = m_currentPanelNode.Previous;

            Trace.WriteLine("Panel switch [<] " + previousPanel.ToString());

            // Mostrar u ocultar el botón Atrás según sea necesario.
            if (previousPanel is Panels.IPanelNoBackButton || m_currentPanelNode.Previous == null)
            {
                BackButton.Hide();
            }
            else
            {
                BackButton.Show();
            }

            // Preparar las animaciones de los Paneles.
            previousPanel.Left    = -previousPanel.Width;
            previousPanel.Enabled = true;
            previousPanel.CreateControl();
            previousPanel.Show();
            previousPanel.BringToFront();

            currentPanel.Enabled = false;

            var animateNext = new EventHandler((Object s1, EventArgs e1) => {
                MainPanel.StopAnimation("Height", "Width");
                MainPanel.AnimateProperty <Animation.EaseInOutBack>("Width", previousPanel.Width);
                MainPanel.AnimateProperty <Animation.EaseInOutBack>("Height", previousPanel.Height).AnimationFinished +=
                    (Object s2, EventArgs e2) => {
                    previousPanel.AnimateProperty <Animation.EaseInOutElastic>("Left", 0).AnimationFinished +=
                        (Object s3, EventArgs e3) => {
                        // Ejecutar el evento de navegación en el Panel anterior.
                        if (currentPanel is Panels.IPanelPreviousEvent)
                        {
                            (currentPanel as Panels.IPanelPreviousEvent).OnPreviousPanelNavigation();
                        }
                    };
                };
            });

            var animator           = currentPanel.GetCurrentAnimator("Left");
            var currentPanelOffset = (currentPanel.Width > previousPanel.Width ? currentPanel.Width : previousPanel.Width) + 30;

            if (animator == null)
            {
                animator = currentPanel.AnimateProperty <Animation.EaseInOutElastic>("Left", currentPanelOffset);
                animator.AnimationFinished += animateNext;
            }
            else
            {
                animator.AnimationFinished += (Object s2, EventArgs e2) =>
                                              currentPanel.AnimateProperty <Animation.EaseInOutElastic>("Left", currentPanelOffset).AnimationFinished +=
                    animateNext;
            }

            return(previousPanel);
        }