how to avoid open page already exist on Navigation stack? [duplicate]
Asked Answered
J

1

5

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(); 
};
Jarvey answered 21/2, 2017 at 18:41 Comment(2)
Just noticed this was responded already with a nicer solution: https://mcmap.net/q/1922615/-pressing-buttons-multiple-times-loads-multiple-pages-androidChord
yes, i see .thanksJarvey
C
14
if (Navigation.NavigationStack.Count == 0 ||
    Navigation.NavigationStack.Last().GetType() != typeof(CustomerPage))
{
    await Navigation.PushAsync(new CustomerPage(), true);
}
Chord answered 21/2, 2017 at 20:56 Comment(2)
it is working fine .. thanksJarvey
var _appNavi = App.NavigationPage.Navigation; if (_appNavi.NavigationStack.Count == 0 || _appNavi.NavigationStack.Last().GetType() != typeof(RankPage)) { await _appNavi.PopToRootAsync(); await _appNavi.PushAsync(new RankPage(), true); } //App.NavigationPage.Navigation.PushAsync(new RankPage()); App.MenuIsPresented = false;Gettings

© 2022 - 2024 — McMap. All rights reserved.