Microsoft Ignite 2019
Miss the Application Development Keynote? Don’t fret, catch it, and more great content on demand.

Xamarin Tutorial - Hello World in 10 minutes

Edit your code

Now you'll add a button to the user interface, along with a click event that will increase and display a count.

Stop debugging

From the menu, select Debug -> Stop Debugging.

From the menu, select Run -> Stop Debugging.

Add a button

Open MainPage.xaml and add the following code under the <Label ... />:

MainPage.xaml
<Button Text="Click Me" Clicked="Handle_Clicked" />

Add an event handler

Open MainPage.xaml.cs and add the following code inside of the class:

MainPage.xaml.cs
int count = 0;
void Handle_Clicked(object sender, System.EventArgs e)
{
    count++;
    ((Button)sender).Text = $"You clicked {count} times.";
}

Run the application

From the menu, select Debug -> Start Debugging.

From the menu, select Run -> Start Debugging.

When you app launches, click the button. The number of clicks will be displayed in the main label.

The Android app running with a button that can be clicked.

Video walkthrough

The iOS and Android apps running with a button that can be clicked

Video walkthrough

Continue