【发布时间】:2013-11-08 16:29:46
【问题描述】:
我正在开发一个显示 XML 文件中的数据并将其显示到 itemgridview 的应用程序。我正在使用 split app 模板。我得到的错误是:
<code>Error: BindingExpression path error: 'rim' property not found on
'System.Runtime.InteropServices.WindowsRuntime.CLRIKeyValuePairImpl`2[
[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, </code>
&
<code>Error: BindingExpression path error: 'carcolor' property not found
on'System.Runtime.InteropServices.WindowsRuntime.CLRIKeyValuePairImpl`2
[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, </code>
Xaml(如果很小,请在新标签中打开): http://i.stack.imgur.com/4r467.png
XML 文件(http://nak-tek.com/test/car.xml)
我的 ItemsPage.cs 代码:
public async void GetXmlAsync()
{
try
{
var client = new HttpClient();
var response = await client.GetAsync("Http://nak-tek.com/test/car.xml");
var text = response.Content.ReadAsStringAsync();
XElement xmlCars = XElement.Parse(text.Result);
IEnumerable<Car> data = from query in xmlCars.Descendants("car")
select new Car
{
carcolor = query.Element("color").Value,
rim = query.Element("rim").Value
};
itemGridView.DataContext = data;
}
catch (Exception)
{ }
}
我的班级Car.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace App2.Common
{
public class Car
{
public string carcolor {get; set;}
public string rim {get; set;}
}
}
【问题讨论】:
-
你能不能也发布一些 xml 示例(xaml 格式的几辆汽车)
-
你可以尝试使用 ToList() 将 IEnumerable 变成一个列表吗?
-
请检查属性拼写。它必须与类定义和 XAML 绑定相同。上面的代码对我有用。
-
@Xyroid 您在使用 Visual Studio 2013 吗?
-
没有,只是资源不同。
标签: c# windows-8 microsoft-metro windows-store-apps windows-8.1