0

我对 Windows Phone 开发完全陌生。实际上,我尝试为我的应用程序实现导航流程。

我想实现这个简单的流程:

  1. 当应用程序启动时,我检查用户是否已经登录
  2. 然后,我导航到 MainPage 等等
  3. 否则我导航到登录页面
  4. 如果登录成功,用户继续登录页面并转到主页

我已经尝试了一些解决方案,例如:

在 App.xaml.cs 中

UriMapper mapper = Resources["uriMapper"] as UriMapper;
RootFrame.UriMapper = mapper;

Uri loginPage = new Uri("/LoginPage.xaml", UriKind.Relative);
Uri mainPage = new Uri("/MainPage.xaml", UriKind.Relative);

if (!ClientApi.IsAuthenticated)
{
    mapper.UriMappings[0].MappedUri = loginPage;
}
else
{
    mapper.UriMappings[0].MappedUri = mainPage;
}

工作,但登录后我无法导航到我的应用程序中的其他页面

我在 MainPage 中覆盖 OnNavigatedTo(NavigationEventArgs e)

if (!App.ClientApi.IsAuthenticated)
{                
    NavigationService.Navigate(new Uri("/LoginPage.xaml", UriKind.Relative));
}

但是当我点击后退按钮时,应用程序不会返回并停留在登录页面上。(我明白为什么。上一页是主页,我覆盖了导致循环的 OnNavigatedTo)

我究竟做错了什么?

PS:

I'm using

4

1 回答 1

0

You need to overwrite the MapUri method of your UriMapper.

The documentation states:

When the app is launched, it assigns the URI mapper during initialization. Before launching any pages, the app calls the MapUri method of the URI mapper to determine which page to launch. The URI that the URI mapper returns is the page that the app launches.

Or you use one of these proposed solutions:

SO

MSDN Blog

Last one seems most fitting.

于 2013-08-20T07:57:16.577 回答