2
votes

i am using xamarin forms and i have a scenario where i have 3 pages(content pages) . In page1 on the click of a button i need to goto page2. and in the the page2 check a flag to decide whether to stay in page2 or redirect to page3. i am trying to do this logic in page 2 constructor and my NavigationStack is coming up as empty. Please suggest.

Page2 constructor:

public Page2()
{
  InitializeComponent();
   If(check==true)
   {    
     Application.Current.MainPage = new NavigationPage(new Page3());
   }
}
2

2 Answers

2
votes
protected override void OnAppearing()
        {
            base.OnAppearing();
            viewModel.InitializeData();
        }

and in intialize data write the if condition

0
votes

You have to use the PushAsync method to not lose the previous stack.. What u're doing is just keeping the stack with minimal size (1 page). Try this code, but you have to await it, so you 're better not doing it the constructor

await Application.Current.MainPage.NavigationPage.PushAsync(new NavigationPage(new Page3()));