c# - 无法从内容页面执行 PopAsync、PopModalAsync 和 PopToRootAsync

标签 c# android xamarin xamarin.forms

我正在使用代码从一个页面导航到另一个页面

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/

相关文章:

android - 如何从 VM 内的 android 模拟器访问 localhost?

c# - 将 SolidColorBrush 绑定(bind)到背景,绑定(bind)错误

c# - 我想要一个单例的设计替代方案

android - 想在 viewpager 上滑动播放声音

java - 在我的自定义 ListView 项上,为什么 (string.length() <= 0) 始终为真,而 (string == "") 始终为假?

php - android in app billing v3 与 php

android - 在第 4 步将 firebase 添加到 firebase 控制台中的应用程序停止

javascript - 为什么 Array.Length = 1 当通过 ajax 将空数组传递给函数时?

C# 从泛型基类中的字段反射 GetValue

c# - 如何限制 MonoTouch 中的 UITextView 字符限制?