Bug 29103 - DisplayAlert and DisplayActionSheet not working properly
Summary: DisplayAlert and DisplayActionSheet not working properly
Alias: None
Product: Forms
Classification: Xamarin
Component: Windows ()
Version: 1.4.1
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2015-04-14 20:11 UTC by J.C.Ködel
Modified: 2015-05-22 23:01 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description J.C.Ködel 2015-04-14 20:11:53 UTC
Only for Windows Phone:

If I try to override OnBackButtonPressed and then ask for a confirmation using DisplayAlert, it returns false BEFORE the user respond to it. For DisplayActionSheet, it aways returns a null string.

The dialog is indeed show, but the answer is not handled (as the await already returned).

In Android, works just fine.

To reproduce:

Create a XAML NavigationPage, then:

protected override bool OnBackButtonPressed()
			Device.BeginInvokeOnMainThread(async () =>
				var result = await DisplayAlert("Encerrar sessão", "Tem certeza de que deseja encerrar esta sessão?", "Sim", "Não");

					App.Instance.OpenPage(new LoginView());

			return true;
Comment 1 Adam 2015-04-21 12:17:56 UTC
I have further information on this. 

The await doesn't work on a DisplayAlert or DisplayActionSheet after changing MainPage in Windows Phone only.

Many other people have this issue to - http://forums.xamarin.com/discussion/30952/displayactionsheet-windows-phone-problem

Some more information on my issue in the forums here - http://forums.xamarin.com/discussion/38579/await-displayalert-not-blocking
Comment 2 Jason Smith [MSFT] 2015-05-22 19:58:32 UTC
The OnBackButtonPressed event must be handled immediately. In cannot be handled asynchronously. The OS does not allow you to delay handle the back button event. If you wish to pop a confirmation dialog (and you REALLY shouldn't) you should simply return true and then manually pop/exit if they accept.
Comment 3 Adam 2015-05-22 23:01:19 UTC
Ok my fault for not reading the exact problem the user has but the DisplayAlert and DisplayActionSheet do have some serious problems awaiting (not in a back button scenario) when you change the MainPage.

I filed another bug here: https://bugzilla.xamarin.com/show_bug.cgi?id=30377