I have an application with few views. I want to be able to check if user is logged in when any view appears. I am using Xamarin Forms Labs to implement solution in an Mvvm way. To implement this functionality, I created a baseviewmodel and in its constructor I check for logged in status. If the user is not logged in then I want to pop open the login view. Here is the code I used-
public class AuthenticateBaseViewModel:Xamarin.Forms.Labs.Mvvm.ViewModel,IAuthentication
{
public AuthenticateBaseViewModel ()
{
CheckAuthentication ();
}
#region IAuthentication implementation
public void CheckAuthentication ()
{
if(!App.IsLoggedIn)
Navigation.PushModalAsync<LoginViewModel>();
}
#endregion
}
However Navigation is null and hence I keep getting null reference exception. Even though the BaseViewModel is inheriting from Labs Mvvm class, why is the Navigation null?
Thanks
Apurva