Forum Xamarin.Android

How to access a data Which I entered at a Entry tab on other page?

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();
 }
}
Tagged:

Best Answer

  • LeonLuLeonLu Member, Xamarin Team Xamurai
    Accepted Answer

    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

  • LeonLuLeonLu Member, Xamarin Team Xamurai
    Accepted Answer

    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.

  • BalaVelanBalaVelan Member ✭✭

    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:

        <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" Padding="20"
    VerticalOptions="Center" HorizontalOptions="Fill">
    <Entry x:Name="UserEntry" 
    VerticalOptions="CenterAndExpand"
     InputTransparent="True" IsEnabled="False" IsReadOnly="True"/>
    <Button Text="read_Only" Clicked="Reado_OnClicked"/>
    <Button Text="Remove" Clicked="remove_OnClicked"/>
    </StackLayout>
    

    page1.xaml.cs:

    namespace NSF_app
    {
    public partial class page1
    {
    
    public static string EntryValue = "";
    public page1()
    {
        InitializeComponent();
    }
    private void Reado_OnClicked(object sender, EventArgs e)
    {
        UserEntry.IsReadOnly = true;
        UserEntry.InputTransparent = true;
        UserEntry.IsEnabled = false;
    }
    
    private void remove_OnClicked(object sender, EventArgs e)
    {
        UserEntry.IsReadOnly = false;
        UserEntry.InputTransparent = false;
        UserEntry.IsEnabled = true;
    }
    }
    

    }

Sign In or Register to comment.