We need some code to update the GUI and to keep track of the count. Proceed as follows:
- Open MainPage.xaml.cs.
- Add the following code to the class:
private int _likeCount;
private int _denyCount;
private void UpdateGui()
{
likeLabel.Text = _likeCount.ToString();
denyLabel.Text = _denyCount.ToString();
}
private void Handle_OnLike(object sender, EventArgs e)
{
_likeCount++;
InsertPhoto();
UpdateGui();
}
private void Handle_OnDeny(object sender, EventArgs e)
{
_denyCount++;
InsertPhoto();
UpdateGui();
}
The two fields at the top of the preceding code block keep track of the number of likes and denies. Since they are value-type variables, they default to zero.
To make the changes of these labels show up in the UI, we've created a method called UpdateGui(). This takes the value of the two aforementioned fields and assigns it to the Text properties of both labels.
The two methods that follow are the event...