我想将数据从xml显示到网格
我需要的价值观我得到了这个:
foreach (XElement wid in document.Root.Elements("widget"))
{
MessageBox.Show(wid.Attribute("caption").Value); //variable: nombreWidget
foreach (XElement service in wid.Elements("service"))
{
MessageBox.Show(service.Attribute("caption").Value); //variable: nombreServicio
MessageBox.Show(service.Element("xvalue").Value); //variable: valor
}
}
手动将值添加到我填写的变量中:
public class Widgets
{
public Widgets()
{
Items = new ObservableCollection<WidgetCollectionItem>
{
new WidgetCollectionItem
{
nombreWidget = "Widget", nombreServicio = "Servicio", valor = "valor"
},
new WidgetCollectionItem
{
nombreWidget = "Widget2", nombreServicio = "Servicio2", valor = "valor2"
},
};
}
public ObservableCollection<WidgetCollectionItem> Items { get; set; }
}
public class WidgetCollectionItem
{
public string nombreWidget { get; set; }
public string nombreServicio { get; set; }
public string valor { get; set; }
}
但我想要实现的是在ObservableCollection中输入数据foreach
我尝试将两者混合,在ObservableCollection之后输入foreach,以浏览并输入数据,但不起作用。
解决方案是什么?