I am unable to get a DisplayAlert
popup to show within the OnAppearing
callback of a Xamarin.Forms Page
. Here is what I have tried so far:
protected override void OnAppearing()
{
base.OnAppearing();
this.DisplayAlert("Alert", "Consider yourself alerted", "OK");
}
Considering DisplayAlert
is technically an async
function, returning a Task
, I have also tried the following:
protected async override void OnAppearing()
{
base.OnAppearing();
await this.DisplayAlert("Alert", "Consider yourself alerted", "OK");
}
However, neither seem to work. My guess is it doesn't really make much sense to make OnAppearing
to be async
at all, since it does not return a Task
, and so this turns into a fire-and-forget situation with respect to the calling framework. Same by extension goes for DisplayAlert
in this context. So on the one hand I don't really expect this to work at all, but in case I'm wrong, is it possible to use DisplayAlert
in OnAppearing
?
Update
Seems I failed to provide some context. I'm working from an Xamarin.Forms Shell template; though I have already developed some past the initial template, so it's hard to say at this point to what extent the Shell itself contributes at all. Also, my main target platform is Android.
That all being said, I was able to start a blank app template and try the above code in the otherwise fresh MainPage
-- both worked fine. I still do not know why they do not work in my actual application context, so I am going to do some digging there and report back any findings.