I Have a very similar situation to this guys question in that I have a Login Page which is my MainPage.xaml file but I have another page called SetPassword.xaml that I want
The solution was simple. To do the navigation I could have done it in either App or MainPage as per my question but the reason the navigation wasn't working was because I was trying to navigate to SetPassword.xaml which was a <ContentDialog>
instead of a <Page>
.
I feel embarrassed actually that I didn't even check that but hopefully if this happens to someone else they can check that they're actually trying to navigate to a Page and not any other type of element. How sadly foolish of me!
EDIT:
Here's what my OnLaunched in the App.xaml file looks like where I can now do my check and redirect to a different page based on the value being set.
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
{
rootFrame = new Frame();
rootFrame.CacheSize = 1;
Window.Current.Content = rootFrame;
// The following checks to see if the value of the password is set and if it is not it redirects to the save password page - else it loads the main page.
Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
if (localSettings.Values["myPassword"] == null)
{
rootFrame.Navigate(typeof(SetPassword));
}
else
{
rootFrame.Navigate(typeof(MainPage));
}
}
if (rootFrame.Content == null)
{
if (rootFrame.ContentTransitions != null)
{
this.transitions = new TransitionCollection();
foreach (var c in rootFrame.ContentTransitions)
{
this.transitions.Add(c);
}
}
rootFrame.ContentTransitions = null;
rootFrame.Navigated += this.RootFrame_FirstNavigated;
if (!rootFrame.Navigate(typeof(MainPage), e.Arguments))
{
throw new Exception("Failed to create initial page");
}
}
Window.Current.Activate();
}