Hi
I have an UpcomingJobsPage page as below as well as the corresponding UpcomingJobsViewModel viewmodel. Its doing pretty standard stuff binding a listview to an observable collection and loading data into observable collection from a web api. Unfortunately the web api does not provide async method to load data.
The problem is that when user selects UpcomingJobsPage page from the burger menu the app gets stuck while data is being loaded from web api (line 'UpcomingJobsList = //... Call to web api' below).
What is a more graceful and elegant way to handle this for a better user experience?
Thanks
Regards
UpcomingJobsPage.xaml code:
<RefreshView x:DataType="viewmodels:UpcomingJobsViewModel"
Command="{Binding LoadItemsCommand}" >
<ListView x:Name="UpcomingJobsListView"
ItemsSource="{Binding UpcomingJobsList}" >
...
</ListView>
</RefreshView>
UpcomingJobsViewModel Code:
class UpcomingJobsViewModel : MyViewModel //MyViewModel is derived from baseViewModel with additional properties etc
{
public Command LoadItemsCommand { get; }
ObservableCollection<UpcomingJobs> items;
public ObservableCollection<UpcomingJobs> UpcomingJobsList
{
get { return items; }
set { SetProperty(ref items, value); }
}
public UpcomingJobsViewModel()
{
UpcomingJobsList = new ObservableCollection<UpcomingJobs>();
LoadItemsCommand = new Command(async () => await ExecuteLoadItemsCommand());
}
private async Task ExecuteLoadItemsCommand()
{
await LoadUpcomingJobsAsync();
}
private async Task LoadUpcomingJobsAsync(Expression<Func<UpcomingJobs, bool>> predicate = null)
{
//Load data from web api here
UpcomingJobsList = //... Call to web api
}
}