Silverlight 5 datagrid缺少数据

Silverlight 5 datagrid缺少数据,silverlight,datagrid,Silverlight,Datagrid,我正在尝试将xml数据集绑定到Silverlight数据网格。我的xml中有21行,网格显示标题ok,21行显示没有数据。如果我查看ItemsSource属性,它会显示行日期 由于堆栈溢出所做的编辑,我在发布所有代码时遇到问题。这是关键部分。如果你还需要看其他东西,我会把它作为评论发布 grdData.ItemsSource = cloData.LoadData("Sample.xml") public class clsData { public System.Collections

我正在尝试将xml数据集绑定到Silverlight数据网格。我的xml中有21行,网格显示标题ok,21行显示没有数据。如果我查看ItemsSource属性,它会显示行日期

由于堆栈溢出所做的编辑,我在发布所有代码时遇到问题。这是关键部分。如果你还需要看其他东西,我会把它作为评论发布

grdData.ItemsSource = cloData.LoadData("Sample.xml")

public class clsData
{
    public System.Collections.IEnumerable LoadData(string pName)
    {
        XDocument nutritionsDoc = XDocument.Load(pName);

        List<Nutrition> data = (from nutrition in nutritionsDoc.Descendants("Nutrition")
                                select new Nutrition
                                {
                                    Group = nutrition.Attribute("Group").Value,
                                    Name = nutrition.Attribute("Name").Value,
                                    Quantity = nutrition.Attribute("Quantity").Value
                                }).ToList();

        return data;
    }
}
grdData.ItemsSource=cloData.LoadData(“Sample.xml”)
公共类数据
{
public System.Collections.IEnumerable加载数据(字符串pName)
{
XDocument nutritionsDoc=XDocument.Load(pName);
列表数据=(摘自nutritionsDoc.subjects(“营养”)中的营养部分)
选择新营养
{
组=营养。属性(“组”)。值,
Name=nutrition.Attribute(“Name”).Value,
数量=营养。属性(“数量”)。值
}).ToList();
返回数据;
}
}

我错过了什么?

我刚刚把营养学课变成了一门公共课,它神奇地解决了


Bob

在分配给itemsSource之前,数据是否有值。