Search code examples
c#xamarin.iosxamarin.androidxamarin.formsportable-class-library

how to avoid open page already exist on Navigation stack?


I am using Xamarin.forms, Some times user will click twice on same button, I am search away to avoid open same page twice, maybe disable the button after first click will work fine, but i am searching away to avoid open same page if page already exist on Navigation stack.

btnCustomerPage.Clicked += (object sender, EventArgs e) => 
{
 //CustomerPage already Exist on Navigation Stack,So user already open it.
 Navigation.PushAsync(new CustomerPage(); 
};

Solution

  • if (Navigation.NavigationStack.Count == 0 ||
        Navigation.NavigationStack.Last().GetType() != typeof(CustomerPage))
    {
        await Navigation.PushAsync(new CustomerPage(), true);
    }