I'm encountering a problem with my WP7 app:
I'm trying to make a login page prompt only when the app can't detect any stored username or password values; however, I keep running into a NullReferenceException when I try to navigate to my login page.
My code looks like this, and it's in the contructor:
if (!checkLogin())
{
NavigationService.Navigate(new Uri("/LoginPage.xaml", UriKind.Relative));
}
And checkLogin
is just a function that returns either true or false depending or not the isolated storage settings are set correctly.
Anybody have any suggestions?
Thanks.
Here is what i think you want to do (From Peter Torr's blog).
If you need more clarification here is a piece of code to illustrate that. Assume there are 2 pages A.XAML and B.xaml and you would want to detect in whether to load A.xaml or B.xaml based on checking some login credentials which is stored in the IsolatedStorage,
in App.xaml.cs of your project overwrite
public App()
with:Then create the 2 dummy pages
A.xaml
andB.xaml
so that forA.xaml
you have some logic for saving the login credentials (in this case just a boolean flag):A.XAML:
A.XAML.cs:
Now, when you run the application for the first time, it will load A.xaml because it could not find any login credentials. Then if you click on the button, it will save the login credentials data in IsolatedStorage. Next time, you start the app it will load B.xaml because it detected the login credentials.
I hope this helps.