Hello,
Once the xaml page is displayed, the subsequent lines are processed.
The subsequent lines (using (GetObjectResponse response = await client.GetObjectAsync(request).ConfigureAwait(false))
) are put in GetCount
method in your ViewModel(HomeViewModel
) class, and you call this method in the constructor of HomeViewModel
, which means that this method is called when you create a HomeViewModel
object, and the HomeViewModel
object isn't created until this method has run.
I don't want the page to appear as there is more code to be processed.
You could call the method in Page.OnAppearing method (or Page.Loaded Event) instead of the constructor of ViewModel.
For example:
Page
protected override async void OnAppearing()
{
base.OnAppearing();
HomeViewModel homeViewModel = this.BindingContext as HomeViewModel;
await homeViewModel.GetCount();
}
ViewMode l(I've omitted some methods)
public class HomeViewModel :...
{
public HomeViewModel()
{
// _ = GetCount();
}
public async Task GetCount()
{
...
}
}
Best Regards,
Wenyan Zhang
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.