2
votes

I am working on a simple UWP app. I created an app using Windows Template Studio as Navigation Pane, basic MVVM. I would like that the app starts with a start page (login page in my case) without the NavigationView control (navigation pane), then after a successful login go to normal view with a navigation pane. This is already done as I followed the docs on https://github.com/Microsoft/WindowsTemplateStudio/blob/dev/docs/navigation.md

private ActivationService CreateActivationService()
{
  //This is the default navigation for a NavigationPane project type
  //return new ActivationService(this, typeof(Views.HomePage), new Views.ShellPage());

  //We are going to initialize navigation to a StartPage
  return new ActivationService(this, typeof(Views.StartPage));
}

After a successful login I navigate first to Views.ShellPage and then to Views.HomePage as described and this works fine.

My question is how to navigate back to StartPage and hide the navigation pane when a user logs off? Simple NavigationService.Navigate<Views.StartPage>(); will just navigate to the start page but how to unload shell with the navigation pane? Thank you in advance for any help.

1

1 Answers

0
votes

My question is how to navigate back to StartPage and hide the navigation pane when a user logs off?

When you navigate back the navigation pane is still existed is caused by that current frame is not the root frame, you just navigate inside the shell frame, the navigation pane will always there since it is not inside the shell frame. To resolve this, just set the Frame property of NavigationService to the root frame when logging off, the root frame should be got by Window.Current.Content.

 private void btnlogout_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
 { 
     Frame rootFrame = Windows.UI.Xaml.Window.Current.Content as Frame; 
     NavigationService.Frame = rootFrame;
     NavigationService.Navigate<StartPage>();
 }