Why I am getting Cannot remove root page when it is also the currently displayed page?

JassimRahmaJassimRahma USMember ✭✭✭✭

Hi,

From my MainPage, I am opening:

App.Current.MainPage.Navigation.PushModalAsync(new Xamarin.Forms.NavigationPage(new NewAd()));

and from NewAdd I am opening:

await Navigation.PushModalAsync(new NewAdPhotos(Convert.ToString(data[0].ad_id), selected_sub_category_name));

but I want to remove the NewAd before or after opening NewAdPhotos

I tried this:

await Navigation.PushModalAsync(new NewAdPhotos(Convert.ToString(data[0].ad_id), selected_sub_category_name));

Navigation.RemovePage(this);

but I am getting:

Cannot remove root page when it is also the currently displayed page

How can i solve this please?

Thanks,
Jassim

Best Answers

  • JassimRahmaJassimRahma US ✭✭✭✭
    Accepted Answer

    Not working

    Here is what I tried..

    In NewAd:

    var page = new NewAdPhotos(Convert.ToString(data[0].ad_id), selected_sub_category_name);
    
    page.PopCurrentPage += () =>
    {
        Navigation.PopModalAsync();
    };
    
    await Navigation.PushModalAsync(page);
    

    and in NewAdPhotos:

    public Action PopCurrentPage { set; get; }

    then when closing the NewAdPhotos:

    async void ImageTitleBarCloseTapped(object sender, System.EventArgs e)
    {
        await DisplayAlert("Ad Gallery", "Ad is NOT Published.\n\n.It will be saved in your draft.", "Ok");
    
        await Navigation.PopModalAsync();
        PopCurrentPage?.Invoke();
    }
    

    the NewAdPhotos is getting closed but the NewAd is still shown

Answers

  • JassimRahmaJassimRahma USMember ✭✭✭✭
    Accepted Answer

    Not working

    Here is what I tried..

    In NewAd:

    var page = new NewAdPhotos(Convert.ToString(data[0].ad_id), selected_sub_category_name);
    
    page.PopCurrentPage += () =>
    {
        Navigation.PopModalAsync();
    };
    
    await Navigation.PushModalAsync(page);
    

    and in NewAdPhotos:

    public Action PopCurrentPage { set; get; }

    then when closing the NewAdPhotos:

    async void ImageTitleBarCloseTapped(object sender, System.EventArgs e)
    {
        await DisplayAlert("Ad Gallery", "Ad is NOT Published.\n\n.It will be saved in your draft.", "Ok");
    
        await Navigation.PopModalAsync();
        PopCurrentPage?.Invoke();
    }
    

    the NewAdPhotos is getting closed but the NewAd is still shown

  • LandLuLandLu Member, Xamarin Team Xamurai

    How did you use it in your project?
    Can you offer a sample because it works fine on my side?

  • JassimRahmaJassimRahma USMember ✭✭✭✭

    Sorry @LandLu

    It's beautifully working

    Thank you

Sign In or Register to comment.