private void ContentFrameOnNavigated(object sender, NavigationEventArgs e) { // Show the back button in desktop and tablet applications // Back button in mobile applications is automatic in the nav bar on screen AppService.SetAppViewBackButtonVisibility(ContentFrame.CanGoBack); // If previous page is a FileLinkPage or FolderLinkPage and the current page is of other type if ((this.ViewModel?.ContentViewModel is FileLinkViewModel && !(this.ContentFrame?.Content is FileLinkPage)) || (this.ViewModel?.ContentViewModel is FolderLinkViewModel && !(this.ContentFrame?.Content is FolderLinkPage))) { // Remove the FolderLinkPage from the BackStack if (NavigateService.MainFrame.BackStack.Any()) { NavigateService.MainFrame.BackStack.Remove(NavigateService.MainFrame.BackStack.Last()); } this.ViewModel.MenuItems = MenuItemViewModel.CreateMenuItems(); this.ViewModel.OptionItems = MenuItemViewModel.CreateOptionItems(); } // If current page is a FileLinkPage and the previous page is of other type if (!(this.ViewModel?.ContentViewModel is FileLinkViewModel) && this.ContentFrame?.Content is FileLinkPage) { this.ViewModel.MenuItems = MenuItemViewModel.CreateFileLinkMenuItems(); this.ViewModel.OptionItems = MenuItemViewModel.CreatePublicLinkOptionItems(); } // If current page is a FolderLinkPage and the previous page is of other type if (!(this.ViewModel?.ContentViewModel is FolderLinkViewModel) && this.ContentFrame?.Content is FolderLinkPage) { this.ViewModel.MenuItems = MenuItemViewModel.CreateFolderLinkMenuItems(); this.ViewModel.OptionItems = MenuItemViewModel.CreatePublicLinkOptionItems(); } // Set current content viewmodel as property of the main page // Could be handy in the future this.ViewModel.ContentViewModel = (this.ContentFrame.Content as Page)?.DataContext as BasePageViewModel; if (e.NavigationMode != NavigationMode.Back) { this.ViewModel.NavigateOnMenuItemSelected = false; } // Set current menu or option item this.ViewModel.SelectedItem = this.ViewModel.MenuItems.FirstOrDefault( m => NavigateService.GetViewType(m.TargetViewModel) == ContentFrame.CurrentSourcePageType); this.ViewModel.SelectedOptionItem = this.ViewModel.OptionItems.FirstOrDefault( m => NavigateService.GetViewType(m.TargetViewModel) == ContentFrame.CurrentSourcePageType); this.ViewModel.NavigateOnMenuItemSelected = true; }
/// <summary> /// Navigate to page that holds the specified viewmodel type /// </summary> /// <param name="viewModelType">Type of viewmodel to navigate to</param> /// <param name="action">Optional navigation action parameter</param> /// <param name="parameters">Optional navigation data parameters</param> public void NavigateTo(Type viewModelType, NavigationActionType action = NavigationActionType.Default, IDictionary <NavigationParamType, object> parameters = null) { if (viewModelType == null) { throw new ArgumentNullException(nameof(viewModelType)); } var pageType = NavigateService.GetViewType(viewModelType); if (pageType == null) { throw new ArgumentException("Viewmodel is not bound to a view"); } var navObj = NavigationObject.Create(this.GetType(), action, parameters); OnUiThread(() => this.Navigation.Navigate(pageType, false, navObj)); }