/// <summary> /// Transitions the new <see cref="T:System.Windows.UIElement"/>. /// </summary> /// <param name="newTransition">The <see cref="T:Microsoft.Phone.Controls.ITransition"/> /// for the new <see cref="T:System.Windows.UIElement"/>.</param> /// <param name="navigationInTransition">The <see cref="T:Microsoft.Phone.Controls.NavigationInTransition"/> /// for the new <see cref="T:System.Windows.UIElement"/>.</param> private void TransitionNewContent(ITransition newTransition, TelegramNavigationInTransition navigationInTransition) { if (_oldContentPresenter != null) { _oldContentPresenter.Visibility = Visibility.Collapsed; _oldContentPresenter.Content = null; } if (null == newTransition) { RestoreContentPresenterInteractivity(_newContentPresenter); return; } EnsureStoppedTransition(newTransition); newTransition.Completed += delegate { CompleteTransition(navigationInTransition, _newContentPresenter, newTransition); }; _readyToTransitionToNewContent = false; _storedNavigationInTransition = null; _storedNewTransition = null; PerformTransition(navigationInTransition, _newContentPresenter, newTransition); }
/// <summary> /// Stops the last navigation transition if it's active and a new navigation occurs. /// </summary> private void EnsureLastTransitionIsComplete() { _readyToTransitionToNewContent = false; _contentReady = false; if (_performingExitTransition) { Debug.Assert(_storedOldTransition != null && _storedNavigationOutTransition != null); // If the app calls GoBack on NavigatedTo, we want the old content to be null // because you can't have the same content in two spots on the visual tree. if (_oldContentPresenter != null) { _oldContentPresenter.Content = null; } if (_storedOldTransition != null) { _storedOldTransition.Stop(); } _storedNavigationOutTransition = null; _storedOldTransition = null; if (_storedNewTransition != null) { _storedNewTransition.Stop(); _storedNewTransition = null; _storedNavigationInTransition = null; } _performingExitTransition = false; } }
/// <summary> /// Handles the completion of the exit transition, automatically /// continuing to bring in the new element's transition as well if it is /// ready. /// </summary> /// <param name="sender">The source object.</param> /// <param name="e">The event arguments.</param> private void OnExitTransitionCompleted(object sender, System.EventArgs e) { _readyToTransitionToNewContent = true; _performingExitTransition = false; if (_navigationStopped) { // Restore the old content presenter's interactivity if the navigation is cancelled. CompleteTransition(_storedNavigationOutTransition, _oldContentPresenter, _storedOldTransition); _navigationStopped = false; } else { CompleteTransition(_storedNavigationOutTransition, /*_oldContentPresenter*/ null, _storedOldTransition); } _storedNavigationOutTransition = null; _storedOldTransition = null; if (_contentReady) { ITransition newTransition = _storedNewTransition; TelegramNavigationInTransition navigationInTransition = _storedNavigationInTransition; _storedNewTransition = null; _storedNavigationInTransition = null; TransitionNewContent(newTransition, navigationInTransition); } }
/// <summary> /// Sets a /// <see cref="T:Microsoft.Phone.Controls.NavigationTransition"/> /// to /// <see cref="M:Microsoft.Phone.Controls.TransitionService.NavigationInTransitionProperty"/> /// for a /// <see cref="T:System.Windows.UIElement"/>. /// </summary> /// <param name="element">The <see cref="T:System.Windows.UIElement"/>.</param> /// <param name="value">The <see cref="T:Microsoft.Phone.Controls.NavigationTransition"/>.</param> /// <returns>The </returns> public static void SetNavigationInTransition(UIElement element, TelegramNavigationInTransition value) { if (element == null) { throw new ArgumentNullException("element"); } element.SetValue(NavigationInTransitionProperty, value); }
/// <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; } TelegramNavigationInTransition navigationInTransition = null; ITransition newTransition = null; if (newElement != null) { navigationInTransition = TelegramTransitionService.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; } }