I have a page where I retrieve data from an API in the OnAppearing method:
protected override async void OnAppearing()
{
var content = await _client.GetStringAsync(Url);
var footmarks = JsonConvert.DeserializeObject<List<Footmark>>(content);
_footmarks = new ObservableCollection<Footmark>(footmarks);
listView.ItemsSource = _footmarks;
base.OnAppearing();
}
This works fine, but on the same page I have 2 event handlers where I also need to make the same API call. So it would be best to move this to a function. But how can I do this, because the event handlers cannot be made async?
So ideally I would have OnAppearing like this:
protected override async void OnAppearing()
{
listView.ItemsSource = GetFootmarks();
base.OnAppearing();
}
And then an event handler which calls the same method:
void Handle_Refreshing(object sender, System.EventArgs e)
{
listView.ItemsSource = GetFootmarks();
listView.EndRefresh();
}
How can I do this?