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
NewAd
can't be removed as it is presenting the NewAdPhotos
. Define an action in your NewAdPhotos
when it needs to be dismissed fire the action to pop the ``NewAd` at the same time:
// NewAdPhotos Page public Action PopCurrentPage { set; get; } private async void Button_Clicked(object sender, EventArgs e) { await Navigation.PopModalAsync(); PopCurrentPage?.Invoke(); } // Register the action var page = new NewAdPhotos(Convert.ToString(data[0].ad_id), selected_sub_category_name); page.PopCurrentPage += () => { Navigation.PopModalAsync(); }; await Navigation.PushModalAsync(page);
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
NewAd
can't be removed as it is presenting theNewAdPhotos
. Define an action in yourNewAdPhotos
when it needs to be dismissed fire the action to pop the ``NewAd` at the same time:Not working
Here is what I tried..
In NewAd:
and in NewAdPhotos:
public Action PopCurrentPage { set; get; }
then when closing the NewAdPhotos:
the NewAdPhotos is getting closed but the NewAd is still shown
How did you use it in your project?
Can you offer a sample because it works fine on my side?
Sorry @LandLu
It's beautifully working
Thank you