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?
CodePudding user response:
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.
CodePudding user response:
Try popping the first, before pushing the second:
await Application.Current.MainPage.Navigation.PopModalAsync();
await Application.Current.MainPage.Navigation.PushModalAsync(new IntercomCallPage());