Hello,
I've a problem using messages to drive the navigation from an async call.
I try to explain better. My problem is really simple: I've a login page. In this page I subscribe to navigate when a certain message is received:
MessagingCenter.Subscribe<ViewModelBase,string>(this, HelperClass.LOGIN_SUCCESSFULL, (sender, username) =>
{
ServiceLocator.Current.GetInstance<INavigationService>().NavigateTo(ViewModelLocator.CouponsPageKey, username);
});
Then, in its viewmodel, when a user press the login button, a relaycommand is triggered to make an async call to a WCF, in this way:
public RelayCommand LoginCommand
{
get
{
return _loginCommand
?? (_loginCommand = new RelayCommand(
() =>
{
Loading = true;
HelperClass.ClientWS.LoginAsync(Username, Password);
}));
}
}
When this service has replied the handler is triggered
void ClientWS_LoginCompleted(object sender, ValidazioneUtenteCompletedEventArgs e)
{
var _res = e.Result;
if (_res)
{
MessagingCenter.Send<ViewModelBase, string>(this, HelperClass.LOGIN_SUCCESSFULL, Username);
}
}
I can see that the message is correctly received because with the debugger the navigateTo is executed.
What's the strange?
Is that in this way I can't see my app navigate to the new page, while if inside of my LoginCommand instead to call the
HelperClass.ClientWS.LoginAsync(Username, Password);
I directly send the message the navigation occurs correctly.
What's wrong?
Thank you