private void OpenPickerPage()
        {
            if (null == PickerPageUri)
            {
                throw new ArgumentException("PickerPageUri property must not be null.");
            }

            if (null == _frame)
            {
                // Hook up to necessary events and navigate
                _frame = Application.Current.RootVisual as PhoneApplicationFrame;
                if (null != _frame)
                {
                    _frameContentWhenOpened = _frame.Content;

                    // Save and clear host page transitions for the upcoming "popup" navigation
                    UIElement frameContentWhenOpenedAsUIElement = _frameContentWhenOpened as UIElement;
                    if (null != frameContentWhenOpenedAsUIElement)
                    {
                        _savedNavigationInTransition = TransitionService.GetNavigationInTransition(frameContentWhenOpenedAsUIElement);
                        TransitionService.SetNavigationInTransition(frameContentWhenOpenedAsUIElement, null);
                        _savedNavigationOutTransition = TransitionService.GetNavigationOutTransition(frameContentWhenOpenedAsUIElement);
                        TransitionService.SetNavigationOutTransition(frameContentWhenOpenedAsUIElement, null);
                    }

                    _frame.Navigated         += OnFrameNavigated;
                    _frame.NavigationStopped += OnFrameNavigationStoppedOrFailed;
                    _frame.NavigationFailed  += OnFrameNavigationStoppedOrFailed;

                    _frame.Navigate(PickerPageUri);
                }
            }
        }
        /// <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;
            }
        }
Esempio n. 3
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);
            }
        }