The first app is a simple counting app, it can be used to count things such as glasses of water you’ve drank (or beer).
As you can see the app is pretty simple but it was a great starting point for me getting to know XAML.
Here is the MainPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Tally.MainPage" BackgroundColor="Black">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Text="Tap to count" TextColor="White" FontSize="40" HorizontalOptions="Center" HorizontalTextAlignment="Center" Grid.Row="0"/>
<Label x:Name="CountLabel" Grid.Row="1" HorizontalTextAlignment="Center" VerticalOptions="Center" Text="" FontSize="60" TextColor="White"/>
<Button x:Name="ResetButton" Grid.Row="2" Clicked="ResetButton_OnClicked"
Text="Reset" CornerRadius="15" HeightRequest="40"
BackgroundColor="Black" BorderColor="White" BorderWidth="2" TextColor="White"
Padding="10,0,10,0" Margin="10,0,10,0"></Button>
<ContentView HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
Grid.Row="1"
Grid.Column="0">
<ContentView.GestureRecognizers>
<TapGestureRecognizer Tapped="OnTapped"/>
</ContentView.GestureRecognizers>
</ContentView>
</Grid>
</ContentPage>
And MainPage.xaml.cs
using System;
using Xamarin.Forms;
namespace Tally
{
public partial class MainPage
{
private int _count;
public MainPage()
{
InitializeComponent();
if (Application.Current.Properties.ContainsKey("Count"))
{
_count = Int32.Parse(Application.Current.Properties["Count"].ToString());
UpdateCountLabelText();
}
}
private void ResetButton_OnClicked(object sender, EventArgs e)
{
_count = 0;
UpdateCountLabelText();
}
private void OnTapped(object sender, EventArgs e)
{
_count++;
UpdateCountLabelText();
}
private void UpdateCountLabelText()
{
CountLabel.Text = _count.ToString("N0");
Application.Current.Properties["Count"] = _count;
}
}
}
A good start, see you with the next app.

