Xamarin.Forms如何从弹窗中获取输入的数据window?

Xamarin.Forms how to get the entered data from the pop-up window?

我有一个弹出窗口 window,用户需要在其中输入一些信息:

<pages:PopupPage xmlns="http://xamarin.com/schemas/2014/forms"

. . .
        <StackLayout>
            <Label Text="Enter name" />
            <Entry FontSize="20"
                   Placeholder=" Some_Thing" />
        </StackLayout>
        <StackLayout>
            <Label Text="Enter price" />
            <Entry FontSize="20"
                   Placeholder="250" />
        </StackLayout>
        <Button BackgroundColor="DodgerBlue"
                FontSize="30"
                Text="Save"
                TextColor="White"
                Clicked="new_product"
                />
    </StackLayout>
</pages:PopupPage>

弹窗window调用如下

    private void ShowNewUserPopup(object o, EventArgs e)
    {
        PopupNavigation.Instance.PushAsync(new NewUserPopupPage());
    }

但是我有一个 question.how 我可以从弹出窗口 window 中获取输入的数据吗?在此之前,我尝试了 DisplayPromptAsync 选项并且一切正常 out.But 这次我应该为“结果”变量分配什么?但是由于这是我第一次使用弹出窗口,所以我一点都不擅长,所以我将非常感谢您的帮助:

async void new_product(object sender, EventArgs e)
{
    string result = await DisplayPromptAsync("New product", "name", "add", "cancel");
    if (result != null)
    {
        if (result.Length != 0)
        {
            await App.Database_Product.Create(new Database.Product(result, 100));
            name_colec.ItemsSource = await App.Database_Product.GetAsync();
        }
        else
        {
            await App.Database_Product.Create(new Database.Product());
            name_colec.ItemsSource = await App.Database_Product.GetAsync();
        }
    }

}

您可以通过页面构造函数传递值。例如,当您想要传递您在弹出页面中输入的值并在导航时将其显示在另一个页面中时,页面构造器是一种简单的方法。

在您的弹出页面中设置条目的名称:

 <StackLayout>
    <StackLayout>
        <Label  Text="Enter name" />
        <Entry x:Name="popup_Name" FontSize="20"
               Placeholder="Some_Thing" />
    </StackLayout>
    <StackLayout>
        <Label  Text="Enter price" />
        <Entry  x:Name="popup_Price" FontSize="20"
               Placeholder="250" />
    </StackLayout>
    <Button BackgroundColor="DodgerBlue"
            FontSize="30"
            Text="Save"
            TextColor="White"
            Clicked="new_product"
            />
</StackLayout>

为要导航的页面设置构造函数:

 public Page2(string name, string price)
    {
        InitializeComponent();
        Name.Text = name;//Name if the Label name of Page2
         Price.Text = price;
    }

当你离开弹出页面到另一个页面时传递值。例如,我使用 ContentPage:

  private async void new_product(object sender, EventArgs e)
    {        
        await Navigation.PushAsync(new Page2(popup_Name.Text, popup_Price.Text));
        await PopupNavigation.Instance.PopAllAsync();
    }

更新:

     private async void new_product(object sender, EventArgs e)
    {        
         if (popup_Name.Text!= null)
      {
   
        await App.Database_Product.Create(new Database.Product(popup_Name.Text, 100));
        name_colec.ItemsSource = await App.Database_Product.GetAsync();
    }
    else
    {
        await App.Database_Product.Create(new Database.Product());
        name_colec.ItemsSource = await App.Database_Product.GetAsync();
    }

    }