I have 4 ContentPage in my application portable class PageA PageB PageC PageD
Page a to page b come with
Navigation.InsertPageBefore(new PageB(),this);
await Navigation.PopAsync();
From Page b to Page c redirect from code
Navigation.InsertPageBefore(new PageC(),this);
await Navigation.PopAsync();
From Page C to Page D redirect from code
Navigation.InsertPageBefore(new PageD(),this);
await Navigation.PopAsync();
Now I want to redirect the user from PageD To PageB
Navigation.InsertPageBefore(new PageB(),this);
await Navigation.PopAsync();
I can come from PageA to PageD very smoothly. But trying to return from PageD to PageB I am getting an exception
Error before must be in the pushed stack of the current context
Stack track
at Xamarin.Forms.Internals.NavigationProxy.OnInsertPageBefore (Xamarin.Forms.Page page, Xamarin.Forms.Page before) [0x00020] in D:\\agent_work\\1\\s\\Xamarin.Forms.Core\\NavigationProxy.cs:150 at Xamarin.Forms.Internals.NavigationProxy.InsertPageBefore (Xamarin.Forms.Page page, Xamarin.Forms.Page before) [0x00000] in D:\\agent_work\\1\\s\\Xamarin.Forms.Core\\NavigationProxy.cs:59 at Test.PageD+d__9.MoveNext () [0x0007a] in E:\\Projects\\xamrine\\Source\\TestiOS\\PictureAfterSignature.xaml.cs:433
How can I resolve this issue?
I would recommend you to navigate this way :
Navigation.PushAsync(new PageA());
// In Page A
Navigation.PushAsync(new PageB());
Navigation.RemovePage(this);
// In Page B
Navigation.PushAsync(new PageC());
// In Page C
Navigation.PushAsync(new PageD());
Navigation.RemovePage(this);
Now if you see, PageB and PageD are only Pages in the Navigation stack.
In PageD, when you want to navigate to B, just call :
Navigation.PopAsync();
// PopAsync - removes the most recent page in stack.
Hope this helps!!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.