我在将 xml 文件加载到 Observable Collection 时遇到问题。
我的 XML 看起来像
<?xml version="1.0" encoding="utf-8"?>
<Stock>
<Assortment>
<Item>Адельфан - эзидрекс таб №10</Item>
<Quantity>89</Quantity>
<Price>3.0000</Price>
<Summ>267</Summ>
<Price1>3.0000</Price1>
<Summ1>267</Summ1>
<ValidDate>01.01.2031</ValidDate>
<Manufacturer>КРКА</Manufacturer>
</Assortment>
<Assortment>
<Item>Адельфан - эзидрекс таб №10</Item>
<Quantity>8</Quantity>
<Price>3.0000</Price>
<Summ>24</Summ>
<Price1>3.0000</Price1>
<Summ1>24</Summ1>
<ValidDate>01.01.2019</ValidDate>
<Manufacturer>КРКА</Manufacturer>
</Assortment>
</Stock>
我试过的代码就是这个。
XDocument xml = XDocument.Load(filename);
foreach (XElement xe in xml.Elements("Assortment"))
{
_dummyCollection1.Add(new DummyClass1()
{
Наименование = xe.Element("Item").Value,
Количество = xe.Element("Quantity").Value,
Цена = xe.Element("Price").Value,
Сумма = xe.Element("Summ").Value,
Цена1 = xe.Element("Price1").Value,
Сумма1 = xe.Element("Summ1").Value,
Срокгодности = xe.Element("ValidDate").Value,
Производитель = xe.Element("Manufacturer").Value
});
}
BuyDataGrid.ItemsSource = _dummyCollection1;
我得到空的DataGrid。如何将 xml 传递给 Observable Collection?