I have a main page : HomeVM. When the app starts, I use PushModalAsync for RegistrationVM In my RegistrationVM, I have a button for pushModalAsync -> LoginVM
When the user is connected, I want go back in the VM HomeVM, but impossible, with PopModalAsync, I come back to RegistrationVM.
I would like to close all popmodalasync.
I have tried this
Here in my app.xaml :
var mainPage = (Page)ViewFactory.CreatePage(typeof(HomeVM));
MainPage = new NavigationPage(mainPage)
{
BarBackgroundColor = (Color)Resources["PrimaryColor"],
BarTextColor = Color.White,
};
Navigation = MainPage.Navigation;
protected override void OnStart()
{
var registrationpage = (Page)ViewFactory.CreatePage(typeof(RegistrationVM));
MainPage.Navigation.PushModalAsync(registrationpage);
}
RegistrationVM :
public RegistrationVM()
{
Task.Run(async () => await ConnectionAPI());
}
async Task ConnectionAPI()
{
try
{
applicationContext.Device = mydevice;
await Navigation.PushModalAsync<LoginVM>(async (vm, p) => await vm.InitializeAsync(this));
}
catch (Exception e)
{
Log.Error(e, "Unhandled exception while loading touch points : {e}", e);
}
finally
{
}
}
LoginVM : When the user click on "Login" PreviousVM = RegistrationVM.
async Task Login()
{
try
{
Log.Information("Logging in");
applicationContext.User = employe;
await Navigation.PopModalAsync();
await Navigation.RemoveAsync(previousVM);
}
catch (Exception e)
{
Log.Error(e, "Unhandled exception during log in : {e}", e);
}
finally
{
}
}
I come back to Registration view
I have tried by using "PushAsync" and "PopAsync" and try this in LoginVM.cs : await Navigation.PopToRootAsync();
Nothing works correctly. It always comeback to RegistrationVM.