StackLayout
element from the Main.XAML file and replace it with the following markup:x:Name
attribute on the Label
element and the Clicked
attribute on the Button
element. The x:Name
attribute is there so you can refer to the component in code. You do this so you can update the value as the button is clicked.Clicked
attribute on the button determines which method is called in code when the button is clicked. In this case it will be a method called IncrementCounterClicked
. The method doesn’t exist yet, so don’t worry about warnings from your IDE; you'll create the code for the method next.Clicked
attribute on the Button
element in the layout.MainPage
class in the MainPage.xaml.cs file with the following C# code:InitializeComponent()
is already written for you and is a Xamarin.Forms method for initializing all UI components for the associated XAML file.IncrementCounterClicked
method is fairly straightforward. The sender
parameter is the object that called the method, allowing it to be reused by multiple components. In this case it is only called from a Button
element so the sender will be Button
. EventArgs
allow you to pass data to the method; in this case you don’t require any, so this parameter can be ignored.x:Name
you gave it earlier and set its text property to the string value of your current count. Boom!ContentPage.Resources
tag has been added before the StackLayout
element, which contains a Stylesheet
tag with the Source
attribute set to a styles.css file in the root of the shared project. The attributes on the components, which customize the appearance such as text color and font size, have also been removed.