2017-05-13 41 views
0

我開始Xamarin.Forms Android項目通過簡單地調用:沒有的MainPage添加到導航堆棧

MainPage = new NavigationPage(new HomePage()); 
在App.xaml.cs

正如https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/navigation/hierarchical/

聲明

這會導致HomePage ContentPage實例被推送到 導航堆棧上,在那裏它成爲應用程序的活動頁面和根頁面 。

但是,當我檢查堆棧,其空:

enter image description here

這到底是怎麼回事?爲什麼頁面不在堆棧中?

+0

你看到顯示的頁面? –

+0

@AlessandroCaliaro是的,我認爲everythig似乎工作得很好,我只是好奇,爲什麼它不是他們在文檔 –

+0

中指定的方式,當你看看「Count」?緊接在MainPage = new NavigationPage(new HomePage())之後; ??? –

回答

1

我簡單地創建了一個新的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> 

,並添加這xml.cs

void Handle_Clicked(object sender, System.EventArgs e) 
{ 
    //throw new NotImplementedException(); 
    Application.Current.MainPage.DisplayAlert("Attention", Navigation.NavigationStack.Count.ToString(), "Ok"); 
} 

,我看到NavigationStack的計數爲1 ... The counter is correct

更新

此外,與CarouselPage,我也有同樣的結果

<?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> 

With CarouselPage