如何在 xamarin 中使用 DisplayPromptAsync 方法弹出显示两个文本框?

How to display two text boxes as pop up using DisplayPromptAsync method in xamarin?

当我使用 -

string result = await DisplayPromptAsync("Question 1", "What's your name?");

弹出窗口中只显示一个文本框。但是如何在弹出窗口中显示两个或多个文本框呢?

如有任何帮助,我们将不胜感激。

你不能,因为它不是故意的。您可以通过使用一些弹出插件或根据本机提示创建自定义代码(类似于 Xamarin.Forms 所做的)来创建自定义弹出窗口。

Xamarin 的记录非常慷慨,因为本机 Android 或 iOS 开发人员没有开箱即用的输入字段提示(尽管创建它并不难,但它仍然远远超出了一行代码。

正如 IvanIčin 所说,您可以使用 Rg.Plugins.Popup 创建自定义弹出窗口。

首先,安装 Rg.Plugins.Popup bu nuget 包...,然后创建弹出页面

<pages:PopupPage
x:Class="FormsSample.popup.popup2"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:pages="clr-namespace:Rg.Plugins.Popup.Pages;assembly=Rg.Plugins.Popup">
<pages:PopupPage.Content>
    <StackLayout
        Padding="20,0"
        BackgroundColor="CadetBlue"
        HorizontalOptions="FillAndExpand"
        VerticalOptions="Center">
        <Label Text="Question 1" />
        <Label Text="this is one question!" />
        <Entry />
        <Entry />
        <Button
            x:Name="btnsub"
            Clicked="btnsub_Clicked"
            Text="subit" />
    </StackLayout>
</pages:PopupPage.Content>

</pages:PopupPage>

 public partial class popup2 : PopupPage
{
    public popup2()
    {
        InitializeComponent();
    }

    private void btnsub_Clicked(object sender, EventArgs e)
    {

    }
}

从 contentpage button.click 事件调用此弹出页面。

 private async void btnPopupButton_Clicked(object sender, EventArgs e)
    {
       
        await PopupNavigation.Instance.PushAsync(new popup2());
    }

可以看到截图: