Windows Phone 8.1检查密码设置是否加载新页面

我对这个问题的情况非常类似,因为我有一个登录页面,这是我的MainPage.xaml文件,但我有另一个名为SetPassword.xaml的页面,如果用户尚未设置密码,我想加载它。 基本上这是应用程序在安装后第一次加载。

我花了好几个小时尝试各种不同的解决方案(包括我链接到的那个),但我只是没有到达任何地方,似乎很多解决方案都是针对WP7或WP8而且没有类似的解决方案WP8.1。

这是使用Windows.Storage进行的基本检查,我正在查看是否已设置密码。

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"); } 

如果我将它添加到public MainPage()类,我在调试消息中返回“密码未设置”的应用程序中没有问题,但是this.frame.Navigate(typeof(SetPassword))导航从不加载SetPassword视图。

我也在OnNavigatedTo尝试了这种方法,结果完全相同。

在我的App.xaml文件中,我再次尝试了许多不同的方法,结果相同。 我可以得到调试消息但不是我正在寻找的导航。 我看了在这里实现Application_Launching的方法,以及在RootFrame.Navigating+= RootFrameOnNavigating;上实现条件导航RootFrame.Navigating+= RootFrameOnNavigating; 在这里,但显然我错过了一些东西。

希望你聪明的人可以帮助我根据条件值让我的导航工作?

解决方案很简单。 要进行导航,我可以根据我的问题在App或MainPage中完成导航,但导航无效的原因是因为我试图导航到SetPassword.xaml,这是一个而不是

实际上我觉得我甚至没有检查过这种情况感到尴尬,但希望如果发生在其他人身上,他们可以检查他们是否真的试图导航到一个Page而不是任何其他类型的元素。 我多么可悲愚蠢!

编辑:

这是我在App.xaml文件中的OnLaunched看起来像我现在可以在哪里检查并根据设置的值重定向到不同的页面。

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