0
我不知道这是否是正确的,但努力学习MVVM,它是如何工作等数据绑定XML
目前,用于加载数据的例子是:
this.SavedItems.Add(new SavedBoard() { ID= "1098", UserDescription = "Test" });
我想解析XML并从那里加载数据。
这是我一直在努力,但似乎并没有工作在C#代码:
XDocument doc = XDocument.Load("savedstops.xml");
var data = from query in doc.Descendants("Stops")
select new SavedBoard
{
ID = query.Element("ID").Value,
UserDescription = query.Element("UserDescription").Value
};
this.SavedItems.Add(data);
这是XML文件:
<Stops>
<Stop>
<ID>1022</ID>
<UserDescription>Test</UserDescription>
</Stop>
<Stop>
<ID>1053</ID>
<UserDescription>Test1045</UserDescription>
</Stop>
</Stops>
我要去哪里错了?我也遇到一个错误错误“无法找到源类型的查询模式的实现'System.Collections.Generic.IEnumerable'。'选择'找不到。'您是否缺少'System.Linq'的引用或使用指令? ?”
虽然我在想这个错误不是它不工作的原因,而是代码逻辑本身。
提前致谢!
命名空间是什么让我!谢谢! – ForeverLearning