In this article, we see how to add a content page in Xamarin.Forms project and add some controls with events in that content page.

Step 1:

Create a Xamarin.Forms project with Portable Class Library (PCL) as discussed in my previous article.

Step 2:

Now Right Click on the PCL project and Add > New Item

C:\Users\Kishor Bikram Oli\Desktop\Blogs\20160529\1.png

Inside the Cross-Platform, select Forms XAML Page and name it MainPage and click OK.

C:\Users\Kishor Bikram Oli\Desktop\Blogs\20160529\2.JPG

Step 3:

Now in App.cs file, we call this MainPage inside the App constructor.

C:\Users\Kishor Bikram Oli\Desktop\Blogs\20160529\3.JPG

Step 4:

In the MainPage.xaml, let’s add Text Label and a Button with click event.

Complete Code:

Step 5:

In the code behind MainPage.xaml.cs, we add click event of button:

Step 6:

Now run the application in your android emulator or windows devices. When you click on button, you see the output as:

C:\Users\Kishor Bikram Oli\AppData\Local\Microsoft\Windows\INetCache\Content.Word\wp_ss_20160529_0002.png

That’s it.

Thanks, Happy Coding!

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=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">