📅  最后修改于: 2022-03-11 14:48:44.778000             🧑  作者: Mango
public class ViewModel
{
public ObservableCollection Data { get; set; }
//static async method that behave like a constructor
async public static Task BuildViewModelAsync()
{
ObservableCollection tmpData = await GetDataTask();
return new ViewModel(tmpData);
}
// private constructor called by the async method
private ViewModel(ObservableCollection Data)
{
this.Data = Data;
}
}