Xamarin Forms populate data async on create

OnAppearing is a possible way to do it because you can legitimately use

public async void OnAppearing()
{

}

However it causes many issues such as when you come back from page in front it will run again.

Depending upon what navigation service or style you are using, I created a new event that gets call only when you first get to the page.

In my BaseViewModel.cs the OnNavigated event https://github.com/adamped/xarch-starter/blob/master/Mobile/Base/BaseViewModel.cs

Which is called when you Push the page on to the stack. Basically call this method when you push the page to your NavigationPage.

Alternatively if you want a quick way, use the OnAppearing method but put a flag/bool in there so you can tell when it has already run once and then won't run again.


I get around this by calling the async code in my view model in OnAppearing of the page instead of the constructor. Constructors are for memory allocation not retrieve data asynchronously.

However, if you really wanted to, you could call .Wait() on your task and block the thread. I would NOT recommend this.