Reputation: 1094
I have an application where I can use popup views over the normal windows. For getting the data the user needs to login so I have a token. Has anyone experience with the way if there is no token, show first a view, then go further where you was heading to?
To make it more clear:
public void Init()
{
if (!CheckToken())
{
Task.Run(() => ShowViewModel<InsertPasswordViewModel>())
.ContinueWith(t => GetData());
}
else
{
//Do your thing
GetData();
}
}
The problem now is that the task is run so view is shown and immediately starts GetData but he has no token and crashes.
Any ideas or fixes are welcome
Upvotes: 0
Views: 165
Reputation: 24460
You shouldn't do navigation in Init
. You are essentially navigating away from a page you are in the middle of navigating to. The navigation isn't finished executing when Init
is called.
You are not getting a result from ShowViewModel
either, so you can't rely on that returning anything when you are done with everything in InsertPasswordViewModel
.
What you are probably looking for is navigating to your ViewModel
with some kind of parameter telling where you came from. Then let InsertPasswordViewModel
use that parameter to navigate back once password is OK.
You probably want to modify the View hierarchy too, which you can do through a custom presenter and a set of presentation hints.
Upvotes: 1