/// <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; } }
/// <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 (e.NavigationMode == NavigationMode.Reset // || e.Uri.OriginalString == "app://external/" // || e.Uri.OriginalString.StartsWith("/Protocol?encodedLaunchUri")) //|| e.Uri.OriginalString.Contains("msg_id")) // return; // 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; TelegramNavigationOutTransition navigationOutTransition = null; ITransition oldTransition = null; if (!e.Uri.OriginalString.Contains("msg_id") && !e.Uri.OriginalString.Contains("SecondaryTile") && !e.Uri.OriginalString.StartsWith("/Protocol?encodedLaunchUri") && !e.Uri.OriginalString.Contains("rndParam") && !(e.Uri.OriginalString == "/Views/ShellView.xaml" && e.NavigationMode == NavigationMode.New) && !(e.Uri.OriginalString.StartsWith("/Views/Additional/SettingsView.xaml?Action=DC_UPDATE"))) { navigationOutTransition = TelegramTransitionService.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; } }