C# 主页未添加到导航堆栈
我只需调用以下命令即可启动Xamarin.Forms android项目:C# 主页未添加到导航堆栈,c#,android,navigation,xamarin.forms,C#,Android,Navigation,Xamarin.forms,我只需调用以下命令即可启动Xamarin.Forms android项目: MainPage = new NavigationPage(new HomePage()); 在App.xaml.cs中 如合同中所述 这将导致主页ContentPage实例被推送到 导航堆栈,其中它将成为活动页和根页 应用程序的名称 但当我检查堆栈时,它是空的: 这里发生了什么?为什么页面不在堆栈中?我只是创建了一个新的XF项目 我已将主页xml更改为 <?xml version="1.0" enco
MainPage = new NavigationPage(new HomePage());
在App.xaml.cs中
如合同中所述
这将导致主页ContentPage实例被推送到
导航堆栈,其中它将成为活动页和根页
应用程序的名称
但当我检查堆栈时,它是空的:
这里发生了什么?为什么页面不在堆栈中?我只是创建了一个新的XF项目 我已将主页xml更改为
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:Test" x:Class="Test.TestPage">
<StackLayout>
<Button Text="How many?" Clicked="Handle_Clicked"/>
<Label Text="Welcome to Xamarin Forms!" VerticalOptions="Center" HorizontalOptions="Center" />
</StackLayout>
</ContentPage>
我看到NavigationStack的计数是1。。。
更新
还有一个旋转木马,我得到了同样的结果
<?xml version="1.0" encoding="UTF-8"?>
<CarouselPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Test.TestPage">
<ContentPage>
<StackLayout>
<Button Text = "how many?" Clicked="Handle_Clicked"/>
<Label Text="Red" />
<BoxView Color="Red" VerticalOptions="FillAndExpand" />
</StackLayout>
</ContentPage>
<ContentPage>
<StackLayout>
<Label Text="Green" />
<BoxView Color="Green" VerticalOptions="FillAndExpand" />
</StackLayout>
</ContentPage>
<ContentPage>
<StackLayout>
<Label Text="Blue" />
<BoxView Color="Blue" VerticalOptions="FillAndExpand" />
</StackLayout>
</ContentPage>
</CarouselPage>
我只是创建了一个新的XF项目 我已将主页xml更改为
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:Test" x:Class="Test.TestPage">
<StackLayout>
<Button Text="How many?" Clicked="Handle_Clicked"/>
<Label Text="Welcome to Xamarin Forms!" VerticalOptions="Center" HorizontalOptions="Center" />
</StackLayout>
</ContentPage>
我看到NavigationStack的计数是1。。。
更新
还有一个旋转木马,我得到了同样的结果
<?xml version="1.0" encoding="UTF-8"?>
<CarouselPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Test.TestPage">
<ContentPage>
<StackLayout>
<Button Text = "how many?" Clicked="Handle_Clicked"/>
<Label Text="Red" />
<BoxView Color="Red" VerticalOptions="FillAndExpand" />
</StackLayout>
</ContentPage>
<ContentPage>
<StackLayout>
<Label Text="Green" />
<BoxView Color="Green" VerticalOptions="FillAndExpand" />
</StackLayout>
</ContentPage>
<ContentPage>
<StackLayout>
<Label Text="Blue" />
<BoxView Color="Blue" VerticalOptions="FillAndExpand" />
</StackLayout>
</ContentPage>
</CarouselPage>
你看到展示的页面了吗?@AlessandroCaliaro是的,我看到了,所有的东西似乎都很好,我只是好奇,为什么你看“计数”时,文档中没有说明这一点?紧跟主页之后=新建导航页面(新建主页())???我测试了代码中的一些代码,在另一个模式页面上,以及在主页的其他方法中。到处都是相同的结果你看到展示的页面了吗?@AlessandroCaliaro是的,我看到了,所有的东西似乎都很好,我只是好奇为什么当你看“计数”时,它不是文档中指定的方式?紧跟主页之后=新建导航页面(新建主页())???我测试了代码中的一些代码,在另一个模式页面上,以及在主页的其他方法中。到处都是同样的结果,亚历山德罗。我也有同样的问题@Robert Golusinski<代码>导航。NavigationStack.Count始终为0。可能是什么?很难说。。。你能在github上创建一个回购协议让我看看吗?谢谢你的回答。我查错了堆栈。一切都在模态一中。对不起打扰你了,你好,亚历山德罗。我也有同样的问题@Robert Golusinski<代码>导航。NavigationStack.Count始终为0。可能是什么?很难说。。。你能在github上创建一个回购协议让我看看吗?谢谢你的回答。我查错了堆栈。一切都在模态一中。对不起打扰你了。