Apologise if there is answer for this somewhere else, I can't find any.
I imagine this is a common situation. The first time the user runs the application I want them to be presented with the SignIn.xaml, if they don't have any saved details, else I just want to go straight to the MainPage.xaml.
I'd usually do this by sticking a check in the constructor of the MainPage and if they don't have details navigate away. The problem I have is that
NavigationService.Navigate(new Uri("/SignIn.xaml", UriKind.Relative));
is coming up as a null reference. What am I missing? Is there a proper way to do something like this in WP7?
Thanks
Unfortunately the WP7 navigation framework doesn't handle the "do something on first run" situation very nicely at all.
I suspect the problem you're seeing is that you don't have a NavigationService
yet... but even if you did, you'd have a problem: the user could still hit the "back" button. You can't even work around that, because the user pressing back should exit the app... but there's no way I'm aware of for doing that without already being at the first page naturally when the user hits the back button.
The only workaround I've found for this is to have the "sign-in" view in the same page as the normal first page, and display one or the other conditionally. Yes, it sucks... but it's the only approach I've found which works. If you find another, I'll be happy to hear about it :)
Peter Torr covers page redirections quite well here. Two methods are offered with relative merits covered. Edit: Note you can redirect to a login page, rather then employing the popup suggestion for login handling.
Redirecting an initial navigation - Peter Torr's Blog
I'd also recommend familiarising with his accompanying post on places here.
Introducing the concept of “Places” - Peter Torr's Blog
This address back stack handling (certification consideration) and addresses scenarios such as login pages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With