public bool Navigate(NavigatingCancelEventArgsBase args) { Should.NotBeNull(args, nameof(args)); if (!args.IsCancelable) { return(false); } if (args.NavigationMode == NavigationMode.Remove) { return(TryClose(args.Context)); } var eventArgs = (NavigatingCancelEventArgs)args; //Back button pressed. if (eventArgs.IsBackButtonNavigation) { var sendBackButton = XamarinFormsToolkitExtensions.SendBackButtonPressed?.Invoke(CurrentContent); if (sendBackButton != null) { CurrentContent.SetNavigationContext(args.Context, true); ToolkitServiceProvider.AttachedValueProvider.SetValue(CurrentContent, BackNavHandledKey, null); sendBackButton(); RaiseNavigated(null, null, NavigationMode.Back, args.Context); return(true); } } if (eventArgs.NavigationMode == NavigationMode.Back) { return(GoBack(args.Context)); } // ReSharper disable once AssignNullToNotNullAttribute return(Navigate(eventArgs.Mapping, eventArgs.Parameter, args.Context)); }
private bool NavigateInternal(NavigatingCancelEventArgsBase args) { if (!args.IsCancelable) { return(false); } NavigatingCancelEventArgs originalArgs = ((NavigatingCancelEventArgsWrapper)args).Args; if (originalArgs.NavigationMode == NavigationMode.Back) { _window.GoBack(); return(true); } if (_useUrlNavigation) { if (originalArgs.ExtraData == null) { return(_window.Navigate(originalArgs.Uri)); } return(_window.Navigate(originalArgs.Uri, originalArgs.ExtraData)); } if (originalArgs.ExtraData == null) { return(_window.Navigate(originalArgs.Content)); } return(_window.Navigate(originalArgs.Content, originalArgs.ExtraData)); }
public virtual bool Navigate(NavigatingCancelEventArgsBase args, IDataContext context) { Should.NotBeNull(args, "args"); if (!args.IsCancelable) { return(false); } var eventArgs = (NavigatingCancelEventArgs)args; //Close button pressed. if (eventArgs.IsBackButtonNavigation && XamarinFormsExtensions.SendBackButtonPressed != null) { var sendBackButton = XamarinFormsExtensions.SendBackButtonPressed(CurrentContent as Page); if (sendBackButton != null) { RaiseNavigated(null, null, NavigationMode.Back); sendBackButton(); return(true); } } if (eventArgs.NavigationMode == NavigationMode.Back) { GoBack(); return(true); } // ReSharper disable once AssignNullToNotNullAttribute return(Navigate(eventArgs.Mapping, eventArgs.Parameter, context)); }
bool INavigationService.Navigate(NavigatingCancelEventArgsBase args, IDataContext dataContext) { if (NavigateArgs == null) { return(false); } return(NavigateArgs(args)); }
public virtual void OnNavigating(NavigatingCancelEventArgsBase e) { EventHandler <INavigationService, NavigatingCancelEventArgsBase> handler = Navigating; if (handler != null) { handler(this, e); } }
public bool Navigate(NavigatingCancelEventArgsBase args, IDataContext dataContext) { Should.NotBeNull(args, nameof(args)); var result = NavigateInternal(args); if (result) { ClearNavigationStackIfNeed(dataContext); } return(result); }
private void OnNavigating(NavigatingCancelEventArgsBase args) { if (_ignoreNavigating) { return; } var currentViewModel = CurrentViewModel; if (currentViewModel == null) { return; } _ignoreCloseFromViewModel = true; args.Cancel = true; var context = CreateContextNavigateFrom(currentViewModel, _navigationTargetVm, args); var navigateTask = (_closedFromViewModel || !args.IsCancelable) ? Empty.TrueTask : OnNavigatingFrom(currentViewModel, context); var t = navigateTask.TryExecuteSynchronously(task => { if (task.IsCanceled || !task.Result) { CancelCurrentNavigation(context); return; } if (task.IsFaulted) { var callback = _currentCallback; if (callback != null) { callback.Invoke(OperationResult.CreateErrorResult <bool?>(OperationType.Navigation, currentViewModel, task.Exception, context)); _currentCallback = null; } return; } ThreadManager.InvokeOnUiThreadAsync(() => { try { _ignoreNavigating = true; Renavigate(currentViewModel, context, args); } finally { _ignoreNavigating = false; } }); }); t.TryExecuteSynchronously(task => _ignoreCloseFromViewModel = false); t.WithTaskExceptionHandler(this); }
/// <summary> /// Navigates using cancel event args. /// </summary> public bool Navigate(NavigatingCancelEventArgsBase args) { Should.NotBeNull(args, "args"); var wrapper = (NavigatingCancelEventArgsWrapper)args; if (wrapper.Args.NavigationMode == NavigationMode.Back) { _frame.GoBack(); return(true); } return(Navigate(wrapper.Args.SourcePageType, wrapper.Parameter)); }
/// <summary> /// Navigates using cancel event args. /// </summary> public bool Navigate(NavigatingCancelEventArgsBase args) { Should.NotBeNull(args, "args"); var originalArgs = ((NavigatingCancelEventArgsWrapper)args).Args; if (originalArgs.NavigationMode == NavigationMode.Back) { _frame.GoBack(); return(true); } return(_frame.Navigate(originalArgs.Uri)); }
protected virtual void NavigationServiceOnNavigating(object sender, NavigatingCancelEventArgsBase args) { try { _navigatingCancelArgs = args; OnNavigating(args); } finally { _navigatingCancelArgs = null; } }
protected virtual INavigationContext CreateContextNavigateFrom(NavigatingCancelEventArgsBase args) { IViewModel viewModelFrom = null, viewModelTo = null; if (args.NavigationMode.IsClose()) { viewModelFrom = args.Context.GetData(NavigationConstants.ViewModel); } else { viewModelTo = args.Context.GetData(NavigationConstants.ViewModel); } if (args.NavigationMode == NavigationMode.Remove) { if (viewModelFrom != null) { return(new NavigationContext(NavigationType.Page, NavigationMode.Remove, viewModelFrom, null, this, args.Context)); } Tracer.Error("Possible bug in navigation, navigate with Remove mode without ViewModel"); return(null); } if (viewModelFrom == null) { viewModelFrom = CurrentViewModel; } if (viewModelFrom == null) { return(null); } Guid viewModelId; if (viewModelTo == null && GetViewModelTypeFromParameter(args.Parameter, out viewModelId) != null) { viewModelTo = ViewModelProvider.TryGetViewModelById(viewModelId); } bool doNotTrackViewModelTo = false; if (viewModelTo == null && args.NavigationMode == NavigationMode.Back) { viewModelTo = NavigationDispatcher.GetPreviousOpenedViewModelOrParent(viewModelFrom, NavigationType.Page, out doNotTrackViewModelTo, this); } return(new NavigationContext(NavigationType.Page, args.NavigationMode, viewModelFrom, viewModelTo, this, args.Context) { { NavigationConstants.DoNotTrackViewModelTo, doNotTrackViewModelTo } }); }
private bool NavigateInternal(NavigatingCancelEventArgsBase args) { if (!args.IsCancelable) { return(false); } NavigatingCancelEventArgs originalArgs = ((NavigatingCancelEventArgsWrapper)args).Args; if (originalArgs.NavigationMode == NavigationMode.Back) { _frame.GoBack(); return(true); } return(_frame.Navigate(originalArgs.Uri)); }
private void Renavigate([NotNull] INavigationContext context, NavigatingCancelEventArgsBase args) { if (_navigatingCancelArgs == null) { if (!NavigationService.Navigate(args)) { TryCompleteNavigationTask(args.Context, false); NavigationDispatcher.OnNavigationCanceled(context); } } else { _navigatingCancelArgs.Cancel = false; } }
private bool NavigateInternal(NavigatingCancelEventArgsBase args) { if (!args.IsCancelable) { return(false); } var wrapper = (NavigatingCancelEventArgsWrapper)args; if (wrapper.Args.NavigationMode == NavigationMode.Back) { _frame.GoBack(); return(true); } return(Navigate(wrapper.Args.SourcePageType, wrapper.Parameter, null)); }
public bool Navigate(NavigatingCancelEventArgsBase args) { Should.NotBeNull(args, nameof(args)); if (args.NavigationMode == MugenMvvmToolkit.Models.NavigationMode.Remove) { return(TryClose(args.Context)); } var result = NavigateInternal(args); if (result) { ClearNavigationStackIfNeed(args.Context); } return(result); }
/// <summary> /// Navigates using cancel event args. /// </summary> public virtual bool Navigate(NavigatingCancelEventArgsBase args) { EnsureInitialized(); if (!args.IsCancelable) { return(false); } var eventArgs = ((NavigatingCancelEventArgs)args); if (eventArgs.NavigationMode == NavigationMode.Back) { return(GoBackInternal()); } // ReSharper disable once AssignNullToNotNullAttribute return(Navigate(eventArgs.Mapping, eventArgs.Parameter, null)); }
public virtual bool Navigate(NavigatingCancelEventArgsBase args, IDataContext dataContext) { Should.NotBeNull(args, nameof(args)); if (!args.IsCancelable) { return(false); } var eventArgs = (NavigatingCancelEventArgs)args; if (eventArgs.NavigationMode == NavigationMode.Back) { return(GoBackInternal()); } // ReSharper disable once AssignNullToNotNullAttribute return(Navigate(eventArgs.Mapping, eventArgs.Parameter, dataContext)); }
private void NavigationServiceOnNavigating(object sender, NavigatingCancelEventArgsBase args) { try { if (!args.Context.Contains(NavigatedTaskConstant) && _unobservedNavigationTcs == null) { _unobservedNavigationTcs = new TaskCompletionSource <bool>(); } _navigatingCancelArgs = args; OnNavigating(args); } finally { _navigatingCancelArgs = null; } }
/// <summary> /// Navigates using cancel event args. /// </summary> public virtual bool Navigate(NavigatingCancelEventArgsBase args) { if (!args.IsCancelable) { return(false); } var eventArgs = ((NavigatingCancelEventArgs)args); if (eventArgs.NavigationMode != NavigationMode.Back && eventArgs.Intent == null) { return(Navigate(eventArgs.Mapping, eventArgs.Parameter, null)); } var activity = _currentActivity; GoBack(); return(activity.IsFinishing); }
protected virtual void OnNavigating(NavigatingCancelEventArgsBase args) { if (args.Context.Contains(IgnoreNavigatingConstant)) { return; } var context = CreateContextNavigateFrom(args); if (context == null) { return; } args.Cancel = true; var navigateTask = !args.IsCancelable ? Empty.TrueTask : NavigationDispatcher.OnNavigatingAsync(context); navigateTask.TryExecuteSynchronously(task => { if (!task.IsCanceled && task.IsFaulted) { TryCompleteNavigationTask(args.Context, false); NavigationDispatcher.OnNavigationFailed(context, task.Exception); return; } if (task.IsCanceled || !task.Result) { TryCompleteNavigationTask(args.Context, false); if (!context.NavigationMode.IsClose()) { NavigationDispatcher.OnNavigationCanceled(context); } return; } ThreadManager.Invoke(ExecutionMode.AsynchronousOnUiThread, this, context, args, (@this, ctx, e) => { e.Context.AddOrUpdate(IgnoreNavigatingConstant, null); @this.Renavigate(ctx, e); }); }); }
/// <summary> /// Navigates using cancel event args. /// </summary> public bool Navigate(NavigatingCancelEventArgsBase args) { if (!args.IsCancelable) { return(false); } var eventArgs = ((NavigatingCancelEventArgs)args); if (eventArgs.NavigationMode == NavigationMode.Back) { if (!RaiseNavigating(new NavigatingCancelEventArgs(eventArgs.Mapping, eventArgs.NavigationMode, eventArgs.Parameter))) { return(false); } GoBack(); return(true); } // ReSharper disable once AssignNullToNotNullAttribute return(Navigate(eventArgs.Mapping, eventArgs.Parameter, null)); }
private bool NavigateInternal(NavigatingCancelEventArgsBase args) { if (!args.IsCancelable) { return(false); } if (args is RemoveNavigatingCancelEventArgs) { return(TryClose(args.Context)); } var wrapper = (NavigatingCancelEventArgsWrapper)args; if (wrapper.Args.NavigationMode == NavigationMode.Back) { _lastContext = args.Context; _frame.GoBack(); return(true); } return(Navigate(wrapper.Args.SourcePageType, wrapper.Parameter, args.Context)); }
public bool Navigate(NavigatingCancelEventArgsBase args) { Should.NotBeNull(args, nameof(args)); if (!args.IsCancelable) { return(false); } if (args.NavigationMode == NavigationMode.Remove) { return(TryClose(args.Context)); } if (args.NavigationMode == NavigationMode.Back) { return(GoBack(args.Context)); } var eventArgs = (NavigatingCancelEventArgs)args; // ReSharper disable once AssignNullToNotNullAttribute return(Navigate(eventArgs.Mapping, eventArgs.Parameter, args.Context)); }
public bool Navigate(NavigatingCancelEventArgsBase args) { Should.NotBeNull(args, nameof(args)); if (!args.IsCancelable) { return(false); } if (args.NavigationMode == NavigationMode.Remove) { return(TryClose(args.Context)); } var eventArgs = (NavigatingCancelEventArgs)args; if (eventArgs.NavigationMode != NavigationMode.Back && eventArgs.Mapping != null) { return(Navigate(eventArgs.Mapping, eventArgs.Parameter, eventArgs.Context)); } return(GoBack(args.Context)); }
public virtual bool Navigate(NavigatingCancelEventArgsBase args, IDataContext dataContext) { Should.NotBeNull(args, nameof(args)); if (!args.IsCancelable) { return(false); } var eventArgs = (NavigatingCancelEventArgs)args; if (eventArgs.NavigationMode != NavigationMode.Back && eventArgs.Mapping != null) { return(Navigate(eventArgs.Mapping, eventArgs.Parameter, dataContext)); } var activity = PlatformExtensions.CurrentActivity; if (activity == null) { return(false); } GoBack(); return(activity.IsFinishing); }
public bool Navigate(NavigatingCancelEventArgsBase args, IDataContext dataContext) { Should.NotBeNull(args, nameof(args)); if (args is BackButtonNavigatingEventArgs) { var application = Application.Current; if (application == null) { return(false); } RaiseNavigated(BackButtonNavigationEventArgs.Instance); application.Exit(); return(true); } var result = NavigateInternal(args); if (result) { ClearNavigationStackIfNeed(dataContext); } return(result); }
public bool Navigate(NavigatingCancelEventArgsBase args, IDataContext dataContext) { Should.NotBeNull(args, "args"); #if WINDOWS_PHONE if (args is BackButtonNavigatingEventArgs) { var application = Application.Current; if (application == null) { return(false); } RaiseNavigated(BackButtonNavigationEventArgs.Instance); application.Terminate(); return(true); } #endif bool result = NavigateInternal(args); if (result) { ClearNavigationStackIfNeed(dataContext); } return(result); }
public bool Navigate(NavigatingCancelEventArgsBase args) { Should.NotBeNull(args, nameof(args)); if (!args.IsCancelable) { return(false); } if (args.NavigationMode == MugenMvvmToolkit.Models.NavigationMode.Remove) { return(TryClose(args.Context)); } var wrapper = (NavigatingCancelEventArgsWrapper)args; if (wrapper.Args.NavigationMode == NavigationMode.Back) { _lastContext = args.Context; _frame.GoBack(); return(true); } return(Navigate(wrapper.Args.SourcePageType, wrapper.Parameter, args.Context)); }
/// <summary> /// Navigates using cancel event args. /// </summary> public bool Navigate(NavigatingCancelEventArgsBase args) { Should.NotBeNull(args, "args"); NavigatingCancelEventArgs originalArgs = ((NavigatingCancelEventArgsWrapper)args).Args; if (originalArgs.NavigationMode == NavigationMode.Back) { _window.GoBack(); return(true); } if (_useUrlNavigation) { if (originalArgs.ExtraData == null) { return(_window.Navigate(originalArgs.Uri)); } return(_window.Navigate(originalArgs.Uri, originalArgs.ExtraData)); } if (originalArgs.ExtraData == null) { return(_window.Navigate(originalArgs.Content)); } return(_window.Navigate(originalArgs.Content, originalArgs.ExtraData)); }
private void Renavigate(IViewModel currentViewModel, [NotNull] INavigationContext context, NavigatingCancelEventArgsBase args) { if (CurrentContent != null) { TryCacheViewModel(context, CurrentContent, currentViewModel); } if (_navigatingCancelArgs == null) { if (NavigationService.Navigate(args, _lastContext)) { ClearCacheIfNeed(_lastContext ?? DataContext.Empty, _navigationTargetVm); } else { CancelCurrentNavigation(context); } } else { _navigatingCancelArgs.Cancel = false; } }