Xamarin.Forms DisplayPromptAsync issues in 4.4 & 4.5 for UWP

Published on

I'm in the middle of building a cross platform Xamarin.Forms app for an unattended device that needs to utilize DisplayPromptAsync to capture input from the user.

We're deploying the app to Android and Windows 10 via UWP. 

Testing the application on Android worked fine however I encountered a strange issue when testing on Windows. Basically, when we should be showing a prompt via the DisplayPromptAsync method built into Xamarin.Forms, the input box never appears and the app seems to just freeze in place.

What DisplayPromptAsync Does

DisplayPrompt Async displays an input box for the user to enter some details. The user can either click the cancel button, or type in a value and then click "OK".

You'll see a screenshot from the Android Emulator below. You'll notice that there is a prompt asking for user input and the numerical keyboard that is automatically displayed on Android when we open a prompt.

My code looks like this:

var result = await DisplayPromptAsync("Employee ID",
    "Enter your employee ID", "OK", "Cancel", null,
    8, keyboard: Keyboard.Numeric, "");

Method Parameters

My code is using the following method.

DisplayPromptAsync(string title, string message, string accept = "OK", string cancel = "Cancel", string placeholder = null, int maxLength = -1, Keyboard keyboard = null, string initialValue = "");

It's important to note that we can specify the keyboard type. I only want my users to enter a number, therefore I specify Keyboard.Numeric. Other options include Keyboard.Text, Keyboard.Email & Keyboard.Telephone.

This code works fine on Android & iOS, but the prompt just never shows when you try to run the app on a Windows 10 using UWP.

The Fix

After doing some research, I came across this Github issue where another developer reported the same problem in the Xamarin.Forms repository.

It seems that there was a bug introduced into an earlier version of Xamarin.Forms that broke DisplayPromptAsync on UWP Windows.

The fix is to update the Xamarin.Forms nuget package to version 4.6 or higher.

These are the steps I took in Visual Studio 2019 to fix the issue:

  1. Right click the solution and select "Manage Nuget Packages for Solution".
  2. Click on the "Installed" tab.
  3. Click on Xamarin.Forms.
  4. Tick all required projects, select the latest stable version from the dropdown and click Update.

That should be it. When you run through the DisplayPromptAsync code on Windows 10 UWP you should now see this prompt.


Article Categories: # xamarin.forms # xamarin # .net # c#
Date Published: Apr 29, 2020

About

A tech blog by Andy P. I talk about coding, enterprise software development, tech, games design & other things that interest me.

Signup To The Newsletter

I try to post a new interesting article every saturday.

IT Asset Management

Our friends at AssetPad are building a complete online solution for managing the IT assets within your organisation. With barcodes and documentation tools.