【发布时间】:2021-04-13 10:54:49
【问题描述】:
我有一个模型:
public class BandModel
{
public string BandName { get; set; }
public CountryModel Country { get; set; }
public GenreModel Genre{ get; set; }
public DateTime DateOfBirth { get; set; }
}
还有一个类会返回这些类的列表
public class FullBandProcessor
{
public static async Task<List<BandModel>> LoadFullBandInformation()
{
string url = "http://localhost:11727/api/Bands";
using (HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(url))
{
if (response.IsSuccessStatusCode)
{
List<BandModel> result = await response.Content.ReadAsAsync<List<BandModel>>();
return result;
}
else
{
throw new Exception(response.ReasonPhrase);
}
}
}
}
我需要在 WPF 中显示这些对象的列表,但我不知道该怎么做 - 它在 WPF 中是完全绿色的。
在这里,我尝试在其中使用ObservableCollection、implement get,以便它调用LoadFullBandInformation,以便稍后它可以绑定到xaml 中的这个属性,但有些东西对我不起作用。
private ObservableCollection<BandModel> _BandModels;
public ObservableCollection<BandModel> bandModels
{
get
{
return _BandModels = FullBandProcessor.LoadFullBandInformation();
}
private set
{
}
}
【问题讨论】:
-
当您调用
LoadFullBandInformation()时可能缺少await -
不,等待没有帮助
-
您在此处编写的代码甚至都无法编译,所以我们怎么能调试您看到的不同问题?