Windows Phone 8.1 check if a password is set to load another page

I have a very similar situation to this guys question , because I have a login page, which is my MainPage.xaml file, but I have another page called SetPassword.xaml that I want to load if the user has not set a password yet. In fact, this is the first time the application loads after installing it.

I spent hours on SO trying different solutions (including the one I'm connected to), but I just don't get anything, and it seems like many of the solutions are either for WP7 or for WP8, and nothing like that has been solved for the new WP8.1.

This is a basic check using Windows.Storage, which I do to determine if a password has been set or not.

Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder; if (localSettings.Values["myPassword"] == null) { Debug.WriteLine("Password not set"); this.Frame.Navigate(typeof(SetPassword)); } else { Debug.WriteLine("Password is set, continuing as normal"); } 

If I add this to the public MainPage() class, I have no problem in the application returning "Password not set" in debug messages, however navigating this.frame.Navigate(typeof(SetPassword)) never loads the SetPassword view.

I also tried this method on OnNavigatedTo with exactly the same results.

In my App.xaml file, I also tried several different methods, again, with the same results. I can get a debug message, but not the navigation I'm looking for. I looked at the implementation of the Application_Launching method here , as well as the implementation of conditional navigation on RootFrame.Navigating+= RootFrameOnNavigating; here but obviously I'm missing something.

I hope you are smarter than people who can help me make my navigation work based on conditional values?

+6
source share
1 answer

The solution was simple. To do the navigation, I could do it in the application or MainPage according to my question, but the reason the navigation system did not work was because I was trying to go to SetPassword.xaml, which was <ContentDialog> instead of <Page> ,

I feel really embarrassed that I didn’t even check this, but hopefully if this happens to someone else, they will be able to verify that they are actually trying to go to the page and not some other type of element . How sad stupid of me!

EDIT:

Here is what my OnLaunched in the App.xaml file looks like now I can do my check and redirect to another page based on the set value.

 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(); } 
+5
source

All Articles