C#WPF数据网格-循环中的ExpandooObject

C#WPF数据网格-循环中的ExpandooObject,c#,wpf,datagrid,expandoobject,C#,Wpf,Datagrid,Expandoobject,我对那个代码有一些问题。我做错了什么 List<dynamic> list = new List<dynamic>(); var columnBind = columnBindName(); // {id, n0, n1, etc...} Name of Columns Bind list.Add(new ExpandoObject()); foreach (var c in columnBind) { list[0].c = "something&

我对那个代码有一些问题。我做错了什么

List<dynamic> list = new List<dynamic>();
var columnBind = columnBindName(); // {id, n0, n1, etc...} Name of Columns Bind

list.Add(new ExpandoObject());

foreach (var c in columnBind)
{
    list[0].c = "something";    //not working in Datagrid
    Console.Write(list[0].c);   //in console i have "something"
    list[0].id = "hello";       //working in Datagrid
}
List List=新列表();
var columnBind=columnBindName();//{id、n0、n1等..}绑定列的名称
添加(新的ExpandoObject());
foreach(columnBind中的变量c)
{
列表[0]。c=“something”//在Datagrid中不工作
Console.Write(列表[0].c);//在控制台中我有“某物”
列表[0]。id=“hello”//正在Datagrid中工作
}

假设您想要设置自定义列表中定义的属性名称,并且
columnBindName
是某种
字符串
可枚举的,您可以使用实现
IDictionary
接口的功能,该接口允许您通过字符串名称获取/设置属性值

foreach (var c in columnBind)
{
    (list[0] as IDictionary<string, object>)[c] = "property value";
}
foreach(columnBind中的变量c)
{
(将[0]列为IDictionary)[c]=“属性值”;
}

假设您想要设置自定义列表中定义的属性名称,并且
columnBindName
是某种
字符串
可枚举的,您可以使用实现
IDictionary
接口的功能,该接口允许您通过字符串名称获取/设置属性值

foreach (var c in columnBind)
{
    (list[0] as IDictionary<string, object>)[c] = "property value";
}
foreach(columnBind中的变量c)
{
(将[0]列为IDictionary)[c]=“属性值”;
}

不在DataGrid中工作是什么意思<代码>列表[0]。c是一个不同的
c
,如果这是您的意思,那么它就是循环中的一个。您的对象将有两个属性
c
id
,因此可以从
columnBind
中选择repleace
c
?不在DataGrid中工作是什么意思<代码>列表[0]。c是一个不同的
c
,如果这是您的意思,那么它就是循环中的一个。您的对象将有两个属性
c
id
,因此可以选择从
columnBind