【发布时间】:2019-06-29 16:14:24
【问题描述】:
如何使用 JSON 填充 ObservableCollection?现在桌面应用程序中只有脚本本身和模型。我不明白如何把它绑起来。 运行脚本后我得到它:
{
"records": [
{
"brand_id": "1",
"brand_name": "Gigabyte"
},
{
"brand_id": "2",
"brand_name": "MSI"
},
{
"brand_id": "3",
"brand_name": "Lenovo"
},
{
"brand_id": "4",
"brand_name": "Dell"
},
{
"brand_id": "5",
"brand_name": "Google"
}
]}
我在应用中有一个模型:
public class Brands
{
int brand_id;
string brand_name;
public int Brand_id { get => brand_id; set => brand_id = value; }
public string Brand_name { get => brand_name; set => brand_name = value; }
}
和收藏:
public class BrandsCollection
{
private ObservableCollection<Brands> brands;
public ObservableCollection<Brands> Brands { get => brands; set => brands = value; }
}
【问题讨论】:
标签: c# php json observablecollection wpfdatagrid