我尝试了使用MVVVM绑定两种列表视图的任何一种方法,但无法做到这一点。当我使用2个不同模型的相同API调用2个属性时,它要求我调用await函数。但是我希望这两个属性一次都获取API。
namespace Grading.ViewModel
{
public class GradingViewModel
{
private ObservableCollection<GradingModel> items;
public ObservableCollection<GradingModel> Items
{
get { return items; }
set
{
items = value;
}
}
public GradingViewModel()
{
Items = new ObservableCollection<GradingModel>()
{
};
MyHTTP.GetAllNewsAsync(list =>
{
foreach (GradingModel item in list)
items.Add(item);
});
}
public Details()
{
Items = new ObservableCollection<Details>()
{
};
MyHTTP.GetAllNewsAsync(list =>
{
foreach (Details info in list)
Info.Add(info);
});
}
}
}
答案 0 :(得分:1)
如果要使用多个并行HTTP调用,则必须使用线程
var t1 = //first req
var t2 = //Second reg
await Task.WhenAll(t1, t2);
ApiResponse response1 = t1.Result;
if (response1.IsSuccess)
{
//Success code
}
ApiResponse response2 = t2.Result;
if (response2.IsSuccess)
{
//Success code
}