When my UserLogin
page loads, i want to check for user database, and if it doesn't exist, or can't be read, i want to direct it to NewUser
page.
protected override void OnNavigatedTo(NavigationEventArgs e)
{
CheckForUser();
if (UserExists == false)
this.Frame.Navigate(typeof(NewUser));
}
The problem is that it never navigates to NewUser
, even when i comment out the if
condition.
This happens because your app tries to navigate before the current frame completely loaded. Dispatcher could be a nice solution, but you have to follow the syntax bellow.
using Windows.UI.Core;
The others are correct, but since Dispatcher doesn't work from the view model, here's how to do it there:
you can try this and see if this works
full example
or
if you want to use a 3rd party tool like Telerik try this link as well
Classic Windows Forms, Stunning User Interface
I see you override OnNavigatedTo method but do not call base method. It may be the source of problem. Try calling base method before any logic:
Use Dispatcher.RunIdleAsync to postpone your navigation to another page until UserLogin page is completely loaded.
Navigate
can't be called directly formOnNavigatedTo
method. You should invoke your code throughDispatcher
and it will work: