I want to retrieve a value from the Entry input after clicking an event. How can I retrieve it. Following is my XAML code:
<?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>
And i want to retrieve the data in a submit_Clicked() method.
private void submit_Clicked(object sender, EventArgs e)
{
how?
}
You can get value from Entry.Text
property. For example:
private void submit_Clicked(object sender, EventArgs e)
{
var nameValue = name.Text;
}
private void submit_Clicked(object sender, EventArgs e)
{
Entry entry = e as Entry;
var text=entry.Text;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With