Transition factory for a particular transition family.
Inheritance: DependencyObject
        /// <summary>
        /// Handles the BackKeyPress to stop the animation and go back.
        /// </summary>
        /// <param name="sender">The source object.</param>
        /// <param name="e">The event arguments.</param>
        private void OnBackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)
        {
            // No need to handle backkeypress if exit transition is complete.
            if (_performingExitTransition)
            {
                var oldElement = Content as UIElement;
                if (oldElement == null)
                {
                    return;
                }

                TransitionElement       oldTransitionElement    = null;
                NavigationOutTransition navigationOutTransition = null;
                ITransition             oldTransition           = null;

                navigationOutTransition = TransitionService.GetNavigationOutTransition(oldElement);

                if (navigationOutTransition != null)
                {
                    oldTransitionElement = _isForwardNavigation ? navigationOutTransition.Forward : navigationOutTransition.Backward;
                }
                if (oldTransitionElement != null)
                {
                    oldTransition = oldTransitionElement.GetTransition(oldElement);
                }
                if (oldTransition != null)
                {
                    CompleteTransition(_storedNavigationOutTransition, /*_oldContentPresenter*/ null, _storedOldTransition);
                    TransitionNewContent(oldTransition, null);
                }
            }
        }
        /// <summary>
        /// Handles the Navigating event of the frame, the immediate way to
        /// begin a transition out before the new page has loaded or had its
        /// layout pass.
        /// </summary>
        /// <param name="sender">The source object.</param>
        /// <param name="e">The event arguments.</param>
        private void OnNavigating(object sender, NavigatingCancelEventArgs e)
        {
            // If the current application is not the origin
            // and destination of the navigation, ignore it.
            // e.g. do not play a transition when the
            // application gets deactivated because the shell
            // will animate the frame out automatically.
            if (!e.IsNavigationInitiator)
            {
                return;
            }

            _isForwardNavigation = e.NavigationMode != NavigationMode.Back;

            var oldElement = Content as UIElement;

            if (oldElement == null)
            {
                return;
            }

            EnsureLastTransitionIsComplete();

            FlipPresenters();

            TransitionElement oldTransitionElement = null;
            ITransition       oldTransition        = null;

            NavigationOutTransition navigationOutTransition = TransitionService.GetNavigationOutTransition(oldElement);

            if (navigationOutTransition != null)
            {
                oldTransitionElement = _isForwardNavigation ? navigationOutTransition.Forward : navigationOutTransition.Backward;
            }

            if (oldTransitionElement != null)
            {
                oldTransition = oldTransitionElement.GetTransition(oldElement);
            }

            if (oldTransition != null)
            {
                EnsureStoppedTransition(oldTransition);

                _storedNavigationOutTransition = navigationOutTransition;
                _storedOldTransition           = oldTransition;
                oldTransition.Completed       += OnExitTransitionCompleted;

                _performingExitTransition = true;

                PerformTransition(navigationOutTransition, _oldContentPresenter, oldTransition);

                PrepareContentPresenterForCompositor(_oldContentPresenter);
            }
            else
            {
                _readyToTransitionToNewContent = true;
            }
        }
        /// <summary>
        /// Called when the value of the
        /// <see cref="P:System.Windows.Controls.ContentControl.Content"/>
        /// property changes.
        /// </summary>
        /// <param name="oldContent">The old <see cref="T:System.Object"/>.</param>
        /// <param name="newContent">The new <see cref="T:System.Object"/>.</param>
        protected override void OnContentChanged(object oldContent, object newContent)
        {
            base.OnContentChanged(oldContent, newContent);

            _contentReady = true;

            UIElement oldElement = oldContent as UIElement;
            UIElement newElement = newContent as UIElement;

            // Require the appropriate template parts plus a new element to
            // transition to.
            if (_firstContentPresenter == null || _secondContentPresenter == null || newElement == null)
            {
                return;
            }

            NavigationInTransition navigationInTransition = null;
            ITransition            newTransition          = null;

            if (newElement != null)
            {
                navigationInTransition = TransitionService.GetNavigationInTransition(newElement);
                TransitionElement newTransitionElement = null;
                if (navigationInTransition != null)
                {
                    newTransitionElement = _isForwardNavigation ? navigationInTransition.Forward : navigationInTransition.Backward;
                }
                if (newTransitionElement != null)
                {
                    newElement.UpdateLayout();

                    newTransition = newTransitionElement.GetTransition(newElement);
                    PrepareContentPresenterForCompositor(_newContentPresenter);
                }
            }

            _newContentPresenter.Opacity    = 0;
            _newContentPresenter.Visibility = Visibility.Visible;
            _newContentPresenter.Content    = newElement;

            _oldContentPresenter.Opacity    = 1;
            _oldContentPresenter.Visibility = Visibility.Visible;
            _oldContentPresenter.Content    = oldElement;

            if (_readyToTransitionToNewContent)
            {
                TransitionNewContent(newTransition, navigationInTransition);
            }
            else
            {
                _storedNewTransition          = newTransition;
                _storedNavigationInTransition = navigationInTransition;
            }
        }
        /// <summary>
        /// Handles the Navigating event of the frame, the immediate way to
        /// begin a transition out before the new page has loaded or had its
        /// layout pass.
        /// </summary>
        /// <param name="sender">The source object.</param>
        /// <param name="e">The event arguments.</param>
        private void OnNavigating(object sender, NavigatingCancelEventArgs e)
        {
            _isForwardNavigation = e.NavigationMode != NavigationMode.Back;

            var oldElement = Content as UIElement;

            if (oldElement == null)
            {
                return;
            }

            var asTransitionElement = oldElement as ITransitionCompleted; // temp

            if (asTransitionElement != null)
            {
                asTransitionElement.OnTransitionGoodbyeTemporary();
            }

            FlipPresenters();

            TransitionElement       oldTransitionElement    = null;
            NavigationOutTransition navigationOutTransition = null;
            ITransition             oldTransition           = null;

            navigationOutTransition = TransitionService.GetNavigationOutTransition(oldElement);

            if (navigationOutTransition != null)
            {
                oldTransitionElement = _isForwardNavigation ? navigationOutTransition.Forward : navigationOutTransition.Backward;
            }
            if (oldTransitionElement != null)
            {
                oldTransition = oldTransitionElement.GetTransition(oldElement);
            }
            if (oldTransition != null)
            {
                EnsureStoppedTransition(oldTransition);

                _storedNavigationOutTransition = navigationOutTransition;
                _storedOldTransition           = oldTransition;
                oldTransition.Completed       += OnExitTransitionCompleted;

                PerformTransition(navigationOutTransition, _oldContentPresenter, oldTransition);

                PrepareContentPresenterForCompositor(_oldContentPresenter);
            }
            else
            {
                _readyToTransitionToNewContent = true;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Called when the value of the
        /// <see cref="P:System.Windows.Controls.ContentControl.Content"/>
        /// property changes.
        /// </summary>
        /// <param name="oldContent">The old <see cref="T:System.Object"/>.</param>
        /// <param name="newContent">The new <see cref="T:System.Object"/>.</param>
        protected override void OnContentChanged(object oldContent, object newContent)
        {
            base.OnContentChanged(oldContent, newContent);
            UIElement oldElement = oldContent as UIElement;
            UIElement newElement = newContent as UIElement;

            if (_firstContentPresenter == null || _secondContentPresenter == null || newElement == null)
            {
                return;
            }
            if (_useFirstAsNew)
            {
                _newContentPresenter = _firstContentPresenter;
                _oldContentPresenter = _secondContentPresenter;
            }
            else
            {
                _newContentPresenter = _secondContentPresenter;
                _oldContentPresenter = _firstContentPresenter;
            }
            _useFirstAsNew = !_useFirstAsNew;
            NavigationOutTransition navigationOutTransition = null;
            NavigationInTransition  navigationInTransition  = null;
            ITransition             oldTransition           = null;
            ITransition             newTransition           = null;

            if (oldElement != null)
            {
                navigationOutTransition = TransitionService.GetNavigationOutTransition(oldElement);
                TransitionElement oldTransitionElement = null;
                if (navigationOutTransition != null)
                {
                    oldTransitionElement = _isForwardNavigation ? navigationOutTransition.Forward : navigationOutTransition.Backward;
                }
                if (oldTransitionElement != null)
                {
                    oldTransition = oldTransitionElement.GetTransition(oldElement);
                    _oldContentPresenter.CacheMode        = new BitmapCache();
                    _oldContentPresenter.IsHitTestVisible = false;
                }
            }
            if (newElement != null)
            {
                navigationInTransition = TransitionService.GetNavigationInTransition(newElement);
                TransitionElement newTransitionElement = null;
                if (navigationInTransition != null)
                {
                    newTransitionElement = _isForwardNavigation ? navigationInTransition.Forward : navigationInTransition.Backward;
                }
                if (newTransitionElement != null)
                {
                    newElement.UpdateLayout();
                    newTransition = newTransitionElement.GetTransition(newElement);
                    _newContentPresenter.CacheMode        = new BitmapCache();
                    _newContentPresenter.IsHitTestVisible = false;
                }
            }
            _newContentPresenter.Opacity    = 0;
            _newContentPresenter.Visibility = Visibility.Visible;
            _newContentPresenter.Content    = newElement;
            _oldContentPresenter.Opacity    = 1;
            _oldContentPresenter.Visibility = Visibility.Visible;
            _oldContentPresenter.Content    = oldElement;
            if (oldTransition != null)
            {
                if (oldTransition.GetCurrentState() != ClockState.Stopped)
                {
                    oldTransition.Stop();
                }
                oldTransition.Completed += delegate
                {
                    oldTransition.Stop();
                    _oldContentPresenter.CacheMode        = null;
                    _oldContentPresenter.IsHitTestVisible = true;
                    if (navigationOutTransition != null)
                    {
                        navigationOutTransition.OnEndTransition();
                    }
                    TransitionNewElement(newTransition, navigationInTransition);
                };
                Dispatcher.BeginInvoke(delegate
                {
                    Dispatcher.BeginInvoke(delegate
                    {
                        if (navigationOutTransition != null)
                        {
                            navigationOutTransition.OnBeginTransition();
                        }
                        oldTransition.Begin();
                    });
                });
            }
            else
            {
                TransitionNewElement(newTransition, navigationInTransition);
            }
        }