Frage

I'm totally new to windows phone development. Actually I try to implement my navigation flow for my application.

I want to achieve this simple flow:

  1. When the app start, I check if the user is already logged in
  2. then, I navigate to the MainPage and so on
  3. else I navigate to the login page
  4. the user proceed the login page and go to the main page if the login succeed

I'm already try some solution like:

in 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;
}

Work but I can't navigate to other page in my application after login

I override OnNavigatedTo(NavigationEventArgs e) in my MainPage

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

but when I hit the back button the app doesn't go back and stuck on the login page.(well I understand why. the previous page it's the mainpage and I override the OnNavigatedTo that cause a loop)

What am I doing wrong?

PS:

I'm using

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top