xamarin.forms - 系统无效操作异常: Page must not already have a parent

标签 xamarin.forms navigation master-detail

在我的 Xamarin.Forms 应用程序中,我有以下代码:

while (this.Navigation.ModalStack.Count > 0)
{
    await this.Navigation.PopModalAsync();
}

await Navigation.PushModalAsync(App.MyMasterDetailPage.Value);

在最后一行,我收到错误

System.InvalidOperationException: Page must not already have a parent.

当我已经从 ModalStack 中弹出所有内容时,MyMasterDetailPage 怎么可能有父级?我只将它推送到 ModalStack

最佳答案

A MasterDetailPage is designed to be a root page, and using it as a child page in other page types could result in unexpected and inconsistent behavior. In addition, it's recommended that the master page of a MasterDetailPage should always be a ContentPage instance, and that the detail page should only be populated with TabbedPage, NavigationPage, and ContentPage instances. This will help to ensure a consistent user experience across all platforms.

来源:official documentation

关于xamarin.forms - 系统无效操作异常: Page must not already have a parent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50178222/

相关文章:

xamarin - 如何检查 xamarin 表单的 UI

layout - Xamarin.Forms 网格布局

html - 如何将导航链接设置为与 Logo 相同的高度?

html - 可访问性 (WCAG 2.0)、冗余链接和响应式网站导航

android - 使用新的架构组件 ViewModel 在 fragment 之间共享数据

xamarin - Xamarin.Forms 上的自定义渲染器可以找到 OnElementChanged 方法

c# - 带有菜单/选项卡的 Xamarin Forms 轮播

.net - AJAX 重载页面中的导航和 URL 重写

wpf - 如何在wpf datagrid中显示数据集中的相关数据

asp.net-mvc - 使用 ASP.Net MVC 中的模型绑定(bind)器更新父/子记录