When we refresh the data, we want to show a loading indicator so that the user knows that something is happening. To do this, we will add ActivityIndicator, which is what this control is called in Xamarin.Forms. Let's set this up:
- In the Weather project, open the MainViewModel class.
- Add a Boolean property called IsRefreshing to MainViewModel.
- Set the IsRefreshing property to true at the beginning of the LoadData method.
- At the end of the LoadData method, set the IsRefreshing property to false, as shown in the following code:
private bool isRefreshing;
public bool IsRefreshing
{
get => isRefreshing;
set => Set(ref isRefreshing, value);
}
public async Task LoadData()
{
IsRefreshing = true;
.... // The rest of the code is omitted for brevity
IsRefreshing = false;
}
Now that we have added some code to MainViewModel, we need to bind the IsRefreshing property to a user interface element that will be displayed...