Jordan DeVaney
Jordan DeVaney

Reputation: 13

Xamarin Forms data binding from xaml

I have an <Entry> in xaml, and I want to get that value the user types.

<Entry x:name="enteredInput>

The file with that <Entry> is in startingPage.xaml with a code behind class startingPage.xaml.cs.

Then I would like to transfer that value in the <Label> element of a different xaml, MainPage.xaml.

Upvotes: 1

Views: 97

Answers (1)

Abdul Gani
Abdul Gani

Reputation: 689

In your second page, add another constructor with string parameter. For ex, If your page name is StartingPage.xaml, then add another constructor like below. Inside, assign the incoming value to your label.

public StartingPage(string entryTextFromStartingPage)
    {
        InitializeComponent();
        lblEntryTextDisplay.Text = entryTextFromStartingPage;
    }

From the StartingPage.xaml.cs, add the below code in a button click or any event that you are calling the Main page,

Navigation.PushAsync(new MainPage(enteredInput.Text);

Upvotes: 4

Related Questions