'before必须是NavigationPage(参数' before ')'的子系(在Xamarin/.net Maui中)

taor4pac  于 2022-12-16  发布在  .NET
关注(0)|答案(1)|浏览(142)

我在.Net Maui中创建了一个演示应用程序,希望使用InsertPageBefore方法在导航之前插入一个页面。
引用自here
我位于MainPage并导航到Page 4,但在导航到Page 4之前,我想插入Page 3以使导航堆栈如下所示

  • 主页/第3页/第4页 *

这是导航到第4页的代码

private void Page4ButtonClicked(object sender, EventArgs e)
{
   Navigation.InsertPageBefore(new Page3(),new Page4());
}

我的App.cs代码

public App()
{
    InitializeComponent();

    MainPage = new NavigationPage(new MainPage());
}

我收到的错误消息是**“before必须是NavigationPage的子级(参数”before“)”**

q9rjltbz

q9rjltbz1#

感谢@Json和@ewerspej的评论。
我正在调用Navigation.InsertPageBefore(新页面3(),新页面4());来自主页。
它应该在导航到
Page 4
之后调用。
所以如果你想在导航后在导航堆栈中添加一个页面。
调用**Navigation.InsertPageBefore(新页面3(),this);**方法就像这样。
把这个贴出来作为对其他还困在这个问题上的人的回答。

相关问题