I'm developing a small application with Xamarin Forms, the app requires signed user so MainPage in App constructor is set to LoginPage.
After a user is signed on I'm changing MainPage to AppShell, this part runs smoothly but I need to redirect a user to LoginPage each time when an application was resumed.
My code looks like this:
App.xaml.cs
public App()
{
InitializeComponent();
DependencyService.Register<RestDataStore>();
DependencyService.Register<CredentialsService>();
MainPage = new LoginPage();
}
Redirect in ViewModel of LoginPage to AppShell
public void OnSubmit()
{
...
Application.Current.MainPage = new AppShell();
}
App.xaml.cs
protected override void OnResume()
{
MainPage = new LoginPage();
}
when i do Page changing like this, nothing will happen.
Is there any other way to change MainPage after an application was resumed? What am I doing wrong?
await Navigation.PushAsync (new LoginPage ());
– VahidShirMainPage = new NavigationPage(new LoginPage());
, the redirect to AppShell toApplication.Current.MainPage.Navigation.PushAsync( new AppShell());
and OnResume tovar nav = MainPage.Navigation; await nav.PushAsync(new LoginPage());
but the OnResume redirect doesn't work and now it is throwing exception about Navigating on Android, that I should use NavigationPage. – dzambo