I am a beginner . I want to to get a data from
page1.xaml
and access this data at other .xaml pages like page3.xaml and page 5.xaml.
Here the data I get in 'X:Name= "EntryText1"' will automatically shown in 'X:Name="EntryText3"' . please tell me, What can I do.
Page1.xaml:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="NSF_app.setting"> <StackLayout BackgroundColor="White" "> <Entry x:Name="EntryText1"/> </StackLayout>
page1.xaml.cs:
public partial class page1: ContentPage { public page1() { InitializeComponent(); } }
page3.xaml:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="NSF_app.setting"> <StackLayout BackgroundColor="White" "> <Entry x:Name="EntryText2"/> <Entry x:Name="EntryText3"/> <Entry x:Name="EntryText4"/> </StackLayout>
page3.xaml.cs:
public partial class page3: ContentPage { public page3() { InitializeComponent(); } }
You can create a public static value to store the entry's value, when entry's text changed event was executed, set the new value to the EntryValue
.
public static string EntryValue = ""; private void EntryText1_TextChanged(object sender, TextChangedEventArgs e) { EntryValue = e.NewTextValue; }
In the page1's xaml. You should achieve the TextChanged
event like following code.
<Entry x:Name="EntryText1" TextChanged="EntryText1_TextChanged" />
In the page3, you can get the value and set it by following code.
public Page3() { InitializeComponent(); EntryText2.Text = Page1.EntryValue; }
Xamarin forums are migrating to a new home on Microsoft Q&A!
We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
For more information, please refer to this sticky post.
Answers
You can create a public static value to store the entry's value, when entry's text changed event was executed, set the new value to the
EntryValue
.In the page1's xaml. You should achieve the
TextChanged
event like following code.In the page3, you can get the value and set it by following code.
Xamarin forums are migrating to a new home on Microsoft Q&A!
We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
For more information, please refer to this sticky post.
unable to lock entry:
Here the Entry was automatically empty while I move to another page, I want that the Entry will change or empty only when, I made change on it. what can I do . please tell me
page1.xaml:
page1.xaml.cs:
}