Is there a work around for Android not triggering after PopModalAsync is called while still using a Modal page. Here is an example:
using System;
using Xamarin.Forms;
namespace XamarinForms
{
public class OnAppearingBug : ContentPage
{
Label label;
public OnAppearingBug ()
{
label = new Label {
Text = "Page"
};
Button button = new Button {
Text = "PushModal"
};
button.Clicked += (sender, e) => Navigation.PushModalAsync (new PopModalBug ());
Content = new StackLayout {
Children = { label, button }
};
}
protected override void OnAppearing(){
label.Text = "OnAppearing";
}
}
}
using System;
using Xamarin.Forms;
namespace XamarinForms
{
public class PopModalBug : ContentPage
{
public PopModalBug ()
{
Button button = new Button {
Text = "Pop Back"
};
//Bug: This will not trigger OnAppearing on Android
button.Clicked += (sender, e) => Navigation.PopModalAsync();
Content = new StackLayout {
Children = { button }
};
}
}
}
see also http://forums.xamarin.com/discussion/21417/navigationpage-push-pop-event-sequence-different-across-platforms and http://forums.xamarin.com/discussion/18781/ios-and-android-different-behaviors-for-onappearing
but as of the moment (Xamarin.Forms 1.2.2) the only/best solution is the one propose by CrisWebb above:
on your main page - MessagingCenter.Subscribe(this, "popped", (sender) => { // code to run });
on your modal page - MessagingCenter.Send(this, "popped");
This is an issue as indicated by keith_r.
As an alternative to MessagingCenter you can use Xamarin.Forms.Application events triggered when modal page are pushed or popped.
Application events described here.
In your Xamarin.Forms.Application MyApp class you can keep an handle of your OnAppearingBug Page. In MyApp you can listen for modal page pushing/poppig and commanding OnAppearingBug Page as you wish.
There is a simple work around. For example, my modal page is a Calendar where the user has to select a date before the POP.
So, inside the Modal Page class just create an Event (in my case OnDateSelected) and create a reference from its parent page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With