/// <summary> /// Handles the navigation when we are moving TO a new view/viewmodel. /// </summary> /// <param name="view"></param> /// <param name="viewModel"></param> /// <param name="navMode"></param> /// <param name="parameter"></param> private void HandleOnNavigatingTo(FrameworkElement view, object viewModel, NavigationMode navMode, object parameter) { // See if the ViewModel participates in navigation-aware services. INavigationAware navm = viewModel as INavigationAware; if (navm != null) { IDictionary <string, object> stateDictionary = null; if (StateManager != null) { string key = GenerateStateKey(PageNavigator.ViewModelKeyPrefix); StateManager.LoadObject(key, viewModel); stateDictionary = StateManager.GetDictionary(key, false); } navm.OnNavigatedTo(new NavigatedToEventArgs(navMode, parameter, stateDictionary)); } // See if the VIEW participates in navigation-aware services. INavigationAware naView = view as INavigationAware; if (naView != null) { IDictionary <string, object> stateDictionary = null; if (StateManager != null) { string key = GenerateStateKey(PageNavigator.PageKeyPrefix); stateDictionary = StateManager.GetDictionary(key, false); } naView.OnNavigatedTo(new NavigatedToEventArgs(navMode, parameter, stateDictionary)); } }
protected override void OnStart() { base.OnStart(); var navigationParam = Nav.GetAndRemoveParameter(Intent); _navigationAwareVm?.OnNavigatedTo(navigationParam); }
public override void ViewDidLoad() { base.ViewDidLoad(); App.ActiveView = this; var navParam = this.GetLastNavigationParameter(); _navigationAwareVm?.OnNavigatedTo(navParam); SetupBindings(); }
protected override void OnNavigatedTo(NavigationEventArgs e) { INavigationAware vm = DataContext as INavigationAware; if (vm != null) { vm.OnNavigatedTo(e.Parameter, e.NavigationMode); } base.OnNavigatedTo(e); }
private void ExecuteSearch(string phrase) { var searchBar = SearchBarService.Current; if (searchBar != null) { UriQuery query = new UriQuery(searchBar.Parameters.ToString()); query.Add(SearchBar.ValueParameter, phrase); query.Add(SearchBar.IsFromSearchBarParameter, "true"); IRegion viewRegion = RegionManager.Regions[AppRegions.ViewRegion]; IRegionNavigationService navigation = viewRegion.NavigationService; if (navigation.Journal.CurrentEntry != null) { if (navigation.Journal.CurrentEntry.Uri.OriginalString.StartsWith(searchBar.NavigationUri.OriginalString)) { INavigationAware navAware = null; var activeView = viewRegion.ActiveViews.FirstOrDefault(); if (activeView is INavigationAware) { navAware = activeView as INavigationAware; } else { FrameworkElement element = activeView as FrameworkElement; if (element != null && element.DataContext is INavigationAware) { navAware = element.DataContext as INavigationAware; } } if (navAware != null) { navAware.OnNavigatedFrom(new NavigationContext(navigation, navigation.Journal.CurrentEntry.Uri)); navAware.OnNavigatedTo(new NavigationContext(navigation, new Uri( searchBar.NavigationUri.ToString() + query, UriKind.RelativeOrAbsolute))); return; } } } RegionManager.RequestNavigate(AppRegions.ViewRegion, searchBar.NavigationUri.ToString() + query); } }
private void NotifyOnNavigatedTo(object parameter) { FrameworkElement contentElement = frame.Content as FrameworkElement; if (contentElement == null) { return; } INavigationAware navigationAwareContext = contentElement.DataContext as INavigationAware; if (navigationAwareContext != null) { navigationAwareContext.OnNavigatedTo(parameter); } }
void InvokeOnNavigatedTo(object item, NavigationContext navigationContext) { var navigationAwareItem = item as INavigationAware; if (navigationAwareItem != null) { navigationAwareItem.OnNavigatedTo(navigationContext); } FrameworkElement frameworkElement = item as FrameworkElement; if (frameworkElement != null) { INavigationAware navigationAwareDataContext = frameworkElement.DataContext as INavigationAware; if (navigationAwareDataContext != null) { navigationAwareDataContext.OnNavigatedTo(navigationContext); } } }
private async Task <NavigationResult> HandleViewModelNavigation(INavigationAware fromPageVM, INavigationAware toPageVM, INavigationParameters parameters) { if (fromPageVM != null) { try { fromPageVM.OnNavigatedFrom(parameters); } catch (Exception ex) { return(new NavigationResult() { IsSuccess = false, Exception = ex }); } } if (toPageVM != null) { try { toPageVM.OnNavigatingTo(parameters); toPageVM.OnNavigatedTo(parameters); await toPageVM.OnNavigatedToAsync(parameters); } catch (Exception ex) { return(new NavigationResult() { IsSuccess = false, Exception = ex }); } } return(new NavigationResult() { IsSuccess = true }); }
/// <summary> /// Called when the implementer has been navigated to. /// </summary> /// <param name="args">Provides data for navigation methods and event handlers that cannot cancel the navigation request.</param> private void NavigatedTo(NavigationEventArgs args) { if(previousPage != null) previousPage.OnNavigatedFrom(args); previousPage = GetNavigationAware(args.Content); if (previousPage == null) return; previousPage.OnNavigatedTo(args); }