简体   繁体   中英

Not able to do PopAsync, PopModalAsync and PopToRootAsync from the content page

I'm navigating from one page to another page using the code

await Application.Current.MainPage.Navigation.PushModalAsync(new IntercomRecieveCallPage()); 

And from IntercomRecieveCallPage I'm navigating to IntercomCallPage using the Following code

await Application.Current.MainPage.Navigation.PushModalAsync(new IntercomCallPage());

And from IntercomCallPage I'm trying to do back navigation using the following code

await App.Current.MainPage.Navigation.PopModalAsync();

But I'm getting the following exception

Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

I also tried PopAsync that is the following code

await App.Current.MainPage.Navigation.PopAsync(true);

for that also I get same exception. I tried to clear the navigation stack using the following code

Navigation.RemovePage(rootPage);

But still it doesn't help. I have no clue how to fix this. Any suggestions?

According to the documentation on Modals page popping , simply having .PopModalAsync( ) should suffice.

Like commented, I do not think it would change much, but maybe make sure you are calling both methods from the same namespace (app.Current vs Application.Current).

Testing on my side however, both push and pop seem to work just fine (even with app or Application).

As a next step however, I would suggest testing out your use case with a different page than IntercomCallPage though. Just to rule out the possibility that this page holds a List that would be causing your error on load/reload instead of the navigation call.

Try popping the first, before pushing the second:

await Application.Current.MainPage.Navigation.PopModalAsync();
await Application.Current.MainPage.Navigation.PushModalAsync(new IntercomCallPage());

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM