【发布时间】:2011-11-22 11:23:34
【问题描述】:
大家,
与大多数应用程序一样,如果设置了密码,我需要为我的应用程序包含一个登录页面。该应用程序的预期行为是,只有设置了密码,它才应该导航到 passwordpage.xaml,并且在输入正确的密码时,它应该导航到 mainpage.xaml。如果没有设置密码,应该直接导航到mainpage.xaml。
以下博客建议需要重新导航,以便在 app.xaml.cs 中包含一个检查,以确定应用需要导航到哪个页面。
但现在的问题是,没有从密码页面进行进一步的导航。它在设置密码时导航到密码页面,但在检查密码匹配后,它不会在 mainpage.xaml 上移动,而是返回到 rootframe_navigating 事件处理程序并执行循环。
http://blogs.msdn.com/b/ptorr/archive/2010/08/28/redirecting-an-initial-navigation.aspx
这是app.xaml.cs中的函数
void RootFrame_Navigating(object sender, NavigatingCancelEventArgs e)
{
//throw new NotImplementedException();
if (e.Uri.ToString().Contains("/MainPage.xaml") != true)
return;
CycleManager pCycMan = CycleManager.instance;
bool checkOk = false;
pCycMan.ReadFromIsolatedStorage();
if (pCycMan.GetPasswordEnabled())
{
checkOk = true;
}
e.Cancel = true;
RootFrame.Dispatcher.BeginInvoke(delegate
{
if (checkOk)
RootFrame.Navigate(new Uri("/PasswordPage.xaml", UriKind.Relative));
else
RootFrame.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
});
}
这是写在passwordpage.xaml中按钮点击的函数
private void OnClick(object sender, RoutedEventArgs e)
{
CycleManager pCycMan = CycleManager.instance;
if (pCycMan.GetPassword() == passwordBox1.Password)
{
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
else
{
MessageBox.Show("Incorrect Password");
}
}
有什么建议吗?
阿尔法
【问题讨论】:
标签: windows-phone-7 navigation nullreferenceexception