Reputation: 685
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());
}
}
Upvotes: 2
Views: 776
Reputation: 685
protected override void OnAppearing()
{
base.OnAppearing();
viewModel.InitializeData();
}
and in intialize data write the if condition
Upvotes: 2
Reputation: 1799
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()));
Upvotes: 0