0
votes

I start my Xamarin.Forms android project simply by calling:

    MainPage = new NavigationPage(new HomePage());

in the App.xaml.cs

As stated in the https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/navigation/hierarchical/

This causes the HomePage ContentPage instance to be pushed onto the navigation stack, where it becomes the active page and the root page of the application.

But when i check the stack, its empty:

enter image description here

What is happening here? Why the page is not in the stack?

1
do you see the page on display? - Alessandro Caliaro
@AlessandroCaliaro Yes i do, everythig seems to work just fine, i'm just curious why is it not the way they specified in the documentation - Robert Golusiński
when you take a look to "Count"? immediately after MainPage = new NavigationPage(new HomePage()); ??? - Alessandro Caliaro
I tested in a few placed in the code, on another modal page as well as somewhere in other methods of the MainPage. Everywhere same result - Robert Golusiński

1 Answers

2
votes

I have simply created a new XF project.

I have changed the main page xml to this

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

and add this to xml.cs

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

and I see that NavigationStack's Count is 1... The counter is correct

UPDATE

Also with a CarouselPage, I have the same result

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