Hello,
Firstly, please add RefreshView and set the refreshCommand. When you execute the Command, set refreshView.IsRefreshing=true;
to show the loading icon, then execute RefreshDataAsync method. After RefreshDataAsync finished, set refreshView.IsRefreshing = false;
to hide the loading icon. By the way, you need to execute the refreshView.IsRefreshing = false;
in the Mainthread like following code.
RefreshView refreshView = new RefreshView();
ICommand refreshCommand = new Command(async () =>
{
// IsRefreshing is true to show the loading icon
refreshView.IsRefreshing=true;
// Refresh data here, to execute RefreshDataAsync
await RefreshDataAsync().ContinueWith(t =>
{
//after loading data, set IsRefreshing=false hide the loading icon
MainThread.InvokeOnMainThreadAsync(() =>
{
refreshView.IsRefreshing = false;
});
});
});
refreshView.Command = refreshCommand;
Then set _collectionView to the refreshView.Content
, Add your refreshView to the Grid.
And set BindingContext=this
;
refreshView.Content = _collection;
_content.Add(refreshView);
Content = _content ;
BindingContext=this;
In the end, change your void to Task for your RefreshDataAsync
method.
private async Task RefreshDataAsync()
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.