我有这段代码
public App()
{
...
MainPage = new NavigationPage(content);
App.Navigation.PushAsync(new homePage());
}
PushAsync不起作用,它表示导航未定义,因此我可以向编译器证明导航已定义
答案 0 :(得分:1)
Looks to me like the compiler is right. Your App
won't have a Navigation
property. What you probably need is:
MainPage.Navigation.PushAsync(new homePage());
答案 1 :(得分:0)
另外
Application.Current.MainPage.Navigation.PushAsync(new homePage());
答案 2 :(得分:0)
我的App()设置如下:
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new MasterDetail());
}
我的MasterDetail看起来像这样:
<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="GrowersClassified.Views.Menu.MasterDetail"
xmlns:detail="clr-namespace:GrowersClassified"
xmlns:master="clr-namespace:GrowersClassified.Views.Menu"
Title="">
<MasterDetailPage.Master>
<master:MasterPage x:Name="masterpage"/>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage>
<x:Arguments>
<detail:Index/>
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail>
我认为您的问题可能是使用App.
Navigation.PushAsync(new homePage());
对我来说,无论何时我试图使用它都会出错。