How to Pass Data in Pages using Xamarin.Forms

Xamarin.Forms
img_xamarin

Until now we have seen how to go from one page to another with NavigationPage and Navigation, but it Is not enough in live applications. You also need to pass some information to another page.

In this tutorial we are going to see how to pass data between different pages in Xamarin.Forms.

We simply try to add a Entry (TextBox, TextField) and a Button and when button press it send the text entered to the second page.

Let’s Start:
For this, we will create a new solution, go to new solution select -> C# -> Mobile Apps -> Blank App(Xamarin.Forms Portable) and give it name “PassDataXamarinForms”

xf8.1

Create 2 files that extendsContantPage give it name as “MainPage” and “SecondPage”.

Set NavigationPage to the “MainPage.cs”, if you don’t know about it refer our old tutorial of NavigationPage.

Now in MainPage.cs add a Entry and Button Control:

In Navigation.PushAsync we pass data of Entry in Constructor.
For this we have to change in the Constructor method of SecondPage:

Now just try to build and run the app, if everything is fine you will see your app like:

For iOS:

xf8.2

xf8.3

For Android:

xf8.4

xf8.5

If you like this tutorial then you can download full copy of the code from github

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">