c# - 单击 Xamarin Forms 中的提交按钮后如何从 XAML 获取值?

标签 c# xaml xamarin xamarin.forms

我想在单击一个事件后从 Entry 输入中检索一个值。我怎样才能找回它。以下是我的 XAML 代码:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:HelloWorld"
             x:Class="HelloWorld.MainPage">

    <StackLayout Spacing="10" x:Name="layout">

        <Label Text="Name" VerticalOptions="Start" FontSize="Large"/>

        <Entry x:Name="name" Placeholder="Enter your name"/>


        <Label Text="Password" VerticalOptions="Start" FontSize="Large"/>

        <Entry x:Name="password" IsPassword="True" Placeholder="****"/>

        <Label Text="Date of Birth" VerticalOptions="Start" FontSize="Large"/>
        <DatePicker x:Name="dob"/>

        <Label Text="Gender" VerticalOptions="Start" FontSize="Large"/>

        <Picker x:Name="GenderPicker" HorizontalOptions="FillAndExpand">
            <Picker.Items>
                <x:String>Male</x:String>
                <x:String>Female</x:String>
            </Picker.Items>
        </Picker>

        <Button x:Name="submit" Text="Save" BorderWidth="20" Clicked="submit_Clicked"/>

    </StackLayout>

</ContentPage>

我想在 submit_Clicked() 方法中检索数据。

      private void submit_Clicked(object sender, EventArgs e)
        {
how?
        }

最佳答案

您可以从 Entry.Text 属性中获取值。例如:

private void submit_Clicked(object sender, EventArgs e)
{
     var nameValue = name.Text;
}

关于c# - 单击 Xamarin Forms 中的提交按钮后如何从 XAML 获取值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44110231/

相关文章:

c# - VS 2015 将警告标记为错误

c# - DataTable 中的列消失

c# - 如何在给定场景中分配权重百分比

android - 无法使用oauth登录到Facebook

xamarin - 如何以 xamarin 形式更新可观察集合

c# - 如何使用 View Model 实现代码隐藏功能?

c# - 扩展时更改 Wpf 中 Expander 的 ToggleButton

c# - 使用 BindableObject 实现 IValueConverter 并且绑定(bind)的 Property 始终为默认值

c# - App.xaml 对象引用未设置为对象的实例

c# - 无法在 Bluestacks 上连接/部署 Visual Studio Xamarin