我正在使用代码从一个页面导航到另一个页面
await Application.Current.MainPage.Navigation.PushModalAsync(new IntercomRecieveCallPage());
从 IntercomRecieveCallPage,我使用以下代码导航到 IntercomCallPage
await Application.Current.MainPage.Navigation.PushModalAsync(new IntercomCallPage());
在 IntercomCallPage 中,我尝试使用以下代码进行后退导航
await App.Current.MainPage.Navigation.PopModalAsync();
但是我遇到了以下异常
索引超出范围。必须为非负数且小于集合的大小。 参数名称:索引
我还尝试了 PopAsync,即以下代码
await App.Current.MainPage.Navigation.PopAsync(true);
为此我也遇到了同样的异常。我尝试使用以下代码清除导航堆栈
Navigation.RemovePage(rootPage);
但是仍然没有帮助。我不知道如何解决这个问题。有什么建议吗?
最佳答案
根据 Modals page popping 的文档,只需拥有 .PopModalAsync( ) 就足够了。
就像评论的那样,我认为它不会改变太多,但也许确保您从同一 namespace 调用这两种方法(app.Current 与 Application.Current)。
然而,在我这边进行测试,推送和弹出似乎都工作得很好(即使使用应用程序或应用程序)。
但是,作为下一步,我建议使用与 IntercomCallPage 不同的页面来测试您的用例。只是为了排除此页面包含一个列表的可能性,该列表会导致加载/重新加载而不是导航调用时出现错误。
关于c# - 无法从内容页面执行 PopAsync、PopModalAsync 和 PopToRootAsync,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72963348/