程序运行后先判断是否已经保存了账号,如果没有保存账号就显示登录页面.如果有账号就自动登录跳转到主界面。这样用户按back后就不会显示登录页面了.
打开App.xaml.cs
在public partial class App : Application中加入
bool islogin = false;
修改RootFrame_Navigating(object sender, NavigatingCancelEventArgs e);public void RootFrame_Navigating(object sender, NavigatingCancelEventArgs e)
{
if (e.Uri.ToString().Contains("/MainPage.xaml") != true || islogin)
return;
e.Cancel = true;
string currentUser = "nouser";
try { currentUser = (string)userSettings["currentUser"]; }//从独立存储读取账号信息;
catch { }
RootFrame.Dispatcher.BeginInvoke(delegate
{
if (currentUser != "nouser")
{
islogin = true;
RootFrame.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));//到主界面
}
else
{
RootFrame.Navigate(new Uri("/Login.xaml", UriKind.Relative));//到登录界面
}
});
在private void CompleteInitializePhoneApplication中加入以下代码
RootFrame.Navigated -= CompleteInitializePhoneApplication;
原文地址:http://mxmxm.com/?p=217