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

HarshitaHarshita INMember ✭✭✭

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

Answers

  • Saraswati_ChandraSaraswati_Chandra USMember ✭✭✭

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

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
  • HarshitaHarshita INMember ✭✭✭

    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;
                });
            }
    
  • Saraswati_ChandraSaraswati_Chandra USMember ✭✭✭

    @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".

  • Rohit_ArnavRohit_Arnav USMember ✭✭

    @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!

  • DR_nathouDR_nathou BEMember ✭✭

    @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? :#

  • DR_nathouDR_nathou BEMember ✭✭

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

    PopupStack is elsewhere...
    @IntelliSenseWinsAgain :hushed:

  • Xami3Xami3 PKMember, University ✭✭✭

    @Harshita

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

    @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

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    Should exists a Stack for Modal pages
  • DanBeaulieu.5044DanBeaulieu.5044 USMember

    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;
                                }
                            }
                        }
    
Sign In or Register to comment.