'XamarinForms how to make two input fields in a popup element

Please tell me how to make it possible to add another message to DisplayPromptAsync? that is, one more line to enter, so that there are two of them. Maybe somehow override the method?

enter image description here



Solution 1:[1]

You can achieve it with dependency service , check the sample for iOS

Define a interface

public interface IAlert
{
    //return the input string
    Task<string> showSingle(string title, string message);
    //return the two input strings
    Task<string[]> showMutiple(string title,string message);
}

Implement in platform project

[assembly: Dependency(typeof(Alert))]
namespace ColeForms.iOS
{
    public class Alert : IAlert
    {     
        public Task<string> showSingle(string title, string message)
        {
            var tcs = new TaskCompletionSource<string>();

            string result = "";

            UIAlertController c = UIAlertController.Create(title, message, UIAlertControllerStyle.Alert);
            c.AddTextField((t) => {});

            UIAlertAction action = UIAlertAction.Create("OK", UIAlertActionStyle.Default, (a) => {
                c.DismissModalViewController(true);
                result = c.TextFields[0].Text;
                tcs.SetResult(result);
            });
            c.AddAction(action);

            UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(c, true, null);

            return tcs.Task;
        }

        public Task<string[]> showMutiple(string title, string message)
        {
            var tcs = new TaskCompletionSource<string[]>();

            string[] result = new string[2];

            UIAlertController c = UIAlertController.Create(title, message, UIAlertControllerStyle.Alert);
            c.AddTextField((t) => {});
            c.AddTextField((t) => {});

            UIAlertAction action = UIAlertAction.Create("OK", UIAlertActionStyle.Default, (a) => {
                c.DismissModalViewController(true);

                result[0] = c.TextFields[0].Text;
                result[1] = c.TextFields[1].Text;
                tcs.SetResult(result);
            });
            c.AddAction(action);

            UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(c, true, null);

            return tcs.Task;
        }

    }
}

Invoke in Forms

var result = await DependencyService.Get<IAlert>().showSingle("title","msg");

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ColeX - MSFT