Xamarin- Adding Controls
If you're new to Xamarin.Forms then I would recommend you to head over to my previous post on Getting started with Cross-Platform Mobile App Development
Adding Buttons to a Xamarin Forms Application
After creating a New Xamarin.Forms App, follow along the below steps to get started with adding Buttons in your Application:
- Open MainPage.xml, in Xamarin.Forms App, where the Shared Code resides, under [YourAppName]-> MainPage.xaml.
- Now add the below line of Code right under the Label created...
Code: <Button Text="Click Here" Clicked="myButton_Clicked"/> - Now let's jump right into adding an Event Handler for the Button. Open the MainPage.xaml.cs file (where the backend logic resides) by expanding the current .xaml file from the Solution Explorer.
- Now write the below code in the MainPage Class, after the MainPage Function.
Code:- int count = 0;
void myButton_Clicked(object sender, System.EventArgs e)
{
count++;
((Button)sender).Text = $"You Clicked {count} Times...";
}
- int count = 0;
- Now hit the F5 Key or just the Run Button and see your App in Action
Comments
Post a Comment