Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 75885

How to show current NavigationStack.Count?

$
0
0

Below is a simple program to become familiar with Navigation. Everything works except the values assigned to Label's Text property. NavigationStack.Count and ModalStack.Count which are always zero. Why are they always zero? It must have to do with thread scope. Note, within Commands, the values are correct. How can I display the current Navigation values?

`using System;
using Xamarin.Forms;

namespace NavigationFun
{
public class App : Application
{
public App()
{
MainPage = new NavigationPage(new AppUI());
}
}
public class AppUI : ContentPage
{
public AppUI()
{
Content = new StackLayout
{
Children = {
new Label
{
Text = DateTime.Now + ": NavigationStack.Count:" + Navigation.NavigationStack.Count + " ModalStack.Count:" + Navigation.ModalStack.Count,
},
new Button {
Text = "PushAsync",
Command = new Command(() => Navigation.PushAsync(new AppUI())),
},
new Button {
Text = "PopAsync",
Command = new Command(() => {if (Navigation.NavigationStack.Count > 1) Navigation.PopAsync();}),
},
new Button {
Text = "PushModalAsync",
Command = new Command(() => Navigation.PushModalAsync(new AppUI())),
},
new Button {
Text = "PopModalAsync",
Command = new Command(() => {if (Navigation.ModalStack.Count > 1) Navigation.PopModalAsync();}),
},
new Button {
Text = "PopToRootAsync",
Command = new Command(() => Navigation.PopToRootAsync()),
},
},
};
}
}
}
`


Viewing all articles
Browse latest Browse all 75885

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>