locked
How to check a page is in the navigation stack or not? RRS feed

  • Question

  • User355485 posted

    How to check a content page already have on navigation stack or not in xamarin forms?

    Friday, June 1, 2018 12:47 PM

All replies

  • User42420 posted

    @Harshita : You want to check the last page of navigation? Can you ellaborate what you want to perform/implement??

    Friday, June 1, 2018 12:52 PM
  • User2148 posted

    I think you should use NavigationStack property. https://forums.xamarin.com/discussion/82423/how-to-detect-what-page-is-on-top

    Friday, June 1, 2018 1:04 PM
  • User355485 posted

    I have a loader popup(working on background),some times it failed to Pop properly.and this time user unable to access application.So I want to pop this popup page after 30 seconds.

    private void startTimer()
            {
                int secondsElapsed=0;
                int MaxSeconds = 30;            
                Device.StartTimer(TimeSpan.FromMilliseconds(1000), () =>
                {
                    if (secondsElapsed < MaxSeconds)
                    {
                        secondsElapsed += 1;
                        return true;
                    }
                    else
                    {
                        Navigation.PopPopupAsync();
                        Navigation.PushPopupAsync(new ErrorPopup("Please try again.","Message"));
                    }
                    return false;
                });
            }
    
    Friday, June 1, 2018 1:18 PM
  • User42420 posted

    @Harshita I dont think there is any method PopPopupAsync. Or this might me a typing error. Now, to show a modal(popup) you have to "PushModalAsync" and to remove it you have to "PopModalAsync".

    Thursday, June 7, 2018 12:30 PM
  • User290865 posted

    @Harshita why u r running this loader popup in the background ?? Instead use rg.plugin.popup for creating your custome loader and use it whenever you want to pop it or push it . if need code reply me!

    Friday, July 6, 2018 4:30 AM
  • User349566 posted

    @Harshita Hi! did you solve your problem? I'm using Rg.Plugin.Popup as well. I wanna check if one popup is in NavigationStack. So the app knows it can't push again this popup. Except the popup is actually showing in app. But it can't be found in NavigationStacknor in ModalStack.

    Have Anyone run into this issue? :#

    Friday, November 16, 2018 8:36 AM
  • User349566 posted

    Solved: var daStack = Rg.Plugins.Popup.Services.PopupNavigation.Instance.PopupStack;

    PopupStack is elsewhere... @IntelliSenseWinsAgain :hushed:

    Friday, November 16, 2018 8:47 AM
  • User102046 posted

    @Harshita

    List<Page> pagesLikeMe = Navigation.NavigationStack.Where(p => p is YourPage).ToList();
    
    bool doesPageExists = Navigation.NavigationStack.Any(p => p is YourPage);
    
    Friday, November 16, 2018 9:40 AM
  • User176749 posted

    @Xami3 said: @Harshita

    List<Page> pagesLikeMe = Navigation.NavigationStack.Where(p => p is YourPage).ToList();
    
    bool doesPageExists = Navigation.NavigationStack.Any(p => p is YourPage);
    

    that wont work for modal pages. modal pages doent appear in the navigationstack

    Monday, January 7, 2019 1:41 PM
  • User2148 posted

    Should exists a Stack for Modal pages

    Monday, January 7, 2019 3:03 PM
  • User322929 posted

    You could do something like this:

    var stack = Application.Current.MainPage.Navigation.ModalStack; UserInterfaces.Pages.MyPage page = null; foreach (var item in stack) { if (item is NavigationPage navPage) { if (navPage.CurrentPage is UserInterfaces.Pages.MyPage myPage) { page = myPage; } } }

    Tuesday, March 12, 2019 4:45 PM