Bug 46105 - Using DisplayAlert with a keyboard on WinPhone 8.1 RT results in E_ACCESSDENIED exception
Summary: Using DisplayAlert with a keyboard on WinPhone 8.1 RT results in E_ACCESSDENI...
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.2
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-10-27 23:01 UTC by John Hardman
Modified: 2017-03-28 10:50 UTC (History)
3 users (show)

Tags: WinRT WinPhone DisplayAlert Focus Exception
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:
Status:
RESOLVED FIXED

Description John Hardman 2016-10-27 23:01:34 UTC
On WinPhone 8.1 RT (running in emulator - as currently have a deployment issue to physical 8.1 phones), if a DisplayAlert is shown and the user attempts to close the Alert using the keyboard, the keystroke is not handled by the Alert and instead goes to the page that opened the Alert. In my case, this is resulting in the keystroke activating a button on the page underneath, which unfortunately calls DisplayAlert a second time, with an exception resulting.

The exception is:

"Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"
Windows.UI.Popups.MessageDialog.ShowAsync()
Xamarin.Forms.Platform.WinRT.Platform.<OnPageAlert>d__55.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__3(Object state)
System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore()"

I suspect the exception is a result of DisplayAlert being called twice. However, the cause of that happening is that the dialog that appears when DisplayAlert is called does not handle keyboard use. In this case, I am using the keyboard as I am working with the emulator, but I would assume that this same problem would occur if using a Bluetooth keyboard with my mobile device.

The code that demonstrates the problem is simply the following:

        private async void OnCommand()
        {
            await DisplayAlert("Title", "Message", "Cancel");
        }

which I trigger by pressing the button defined below:

            Button displayAlertButton = new Button
            {
                Text = "Display Alert",
                Command = new DelegateCommand(OnCommand)
            };

When an Alert is displayed, the focus should be passed to the Alert (ideally to the first button on the Alert) rather than remaining on the underlying page.
Comment 1 John Hardman 2016-10-28 09:51:19 UTC
Note that the keypress going to the underlying page instead of the Alert is not limited to WinPhone 8.1 RT.
Comment 2 Jimmy [MSFT] 2017-03-27 21:48:22 UTC
The exception caused by displaying multiple Alerts should be resolved in 2.3.4: https://github.com/xamarin/Xamarin.Forms/pull/347

I was also not able to reproduce the behavior where the keyboard input was activating the button on the page beneath the Alert. I tested with the Popups sample[1] on a W10 mobile emulator using Forms 2.3.3.193 and 2.3.4-pre6. With the Alert open, pressing Enter on the keyboard would activate the Button on the Alert itself. I could also press Tab to switch focus between the "Accept" and "Cancel" buttons if both were present in the Alert.

If you are still experiencing this issue with Forms 2.3.4-pre6 or later, please reopen this issue and include which emulator you are testing with and specific repro steps. Thanks!

[1] https://developer.xamarin.com/samples/xamarin-forms/Navigation/Pop-ups/
Comment 3 John Hardman 2017-03-28 10:50:36 UTC
It was still a problem in 2.3.3.193 . I will re-test when I upgrade to 2.3.4

The emulator is "Emulator 8.1 1080P 6 inch", running on a 64 bit Windows 10 PC.

The code used has a Button on a ContentPage. When the Button is pressed, DisplayAlert is called. Hitting space or Enter activates the Button on the ContentPage, not the button on the alert.