将字符串列表绑定到wpf listview会返回BindingExpression路径错误

时间:2015-06-23 02:19:14

标签: c# wpf listview data-binding

我有两个声明如下的字符串列表:

Config.cs:

foreach (XmlNode skillNameNode in skillNameNodeList) 
{
  agentSkills.agentSkillsNameList.Add(skillNameNode.Attributes["value"].Value);
}

foreach (XmlNode skillLevelNode in skillLevelNodeList) 
{
  agentSkills.agentSkillsLvlList.Add(skillLevelNode.Attributes["value"].Value);
}

我从XML中检索了字符串,并将它们添加到列表中,如下所示:

Config.cs:

Config.AgentSkills abc = new Config.AgentSkills();

this.AInfoLv.Items.Add(new { Label=" " + abc.agentSkillsNameList, Value=" " + abc.agentSkillsLvlList });

然后,我通过了这些列表并将它们绑定到这样的列表视图中:

Info.cs:

System.Windows.Data Error:40:BindingExpression path error:'Value' property not found on'object'''<>f__AnonymousType0`1' (HashCode=2053256737)'. BindingExpression:Path=Value;
 DataItem='<>f__AnonymousType0`1' (HashCode=2053256737);
 target element is'TextBlock' (Name='');
 target property is'Text' (type'String') 
System.Windows.Data Error:40:BindingExpression path error:'Value' property not found on'object'''<>f__AnonymousType0`1' (HashCode=-861434965)'. BindingExpression:Path=Value;
 DataItem='<>f__AnonymousType0`1' (HashCode=-861434965);
 target element is'TextBlock' (Name='');
 target property is'Text' (type'String') 
System.Windows.Data Error:40:BindingExpression path error:'Value' property not found on'object'''<>f__AnonymousType0`1' (HashCode=1323488897)'. BindingExpression:Path=Value;
 DataItem='<>f__AnonymousType0`1' (HashCode=1323488897);
 target element is'TextBlock' (Name='');
 target property is'Text' (type'String') 
System.Windows.Data Error:40:BindingExpression path error:'Value' property not found on'object'''<>f__AnonymousType0`1' (HashCode=-2018970060)'. BindingExpression:Path=Value;
 DataItem='<>f__AnonymousType0`1' (HashCode=-2018970060);
 target element is'TextBlock' (Name='');
 target property is'Text' (type'String') 
System.Windows.Data Error:40:BindingExpression path error:'Value' property not found on'object'''<>f__AnonymousType0`1' (HashCode=249974195)'. BindingExpression:Path=Value;
 DataItem='<>f__AnonymousType0`1' (HashCode=249974195);
 target element is'TextBlock' (Name='');
 target property is'Text' (type'String')

但它返回错误如下:

model1_obj = xx.objects.filter(
    date_generated__gte=1429142401,
    date_generated__lte=1431648001,
    s__icontains="28"
)

将字符串列表绑定到wpf中的列表视图是否可以?如果不能,这个问题是否有任何建议?

1 个答案:

答案 0 :(得分:2)

但是您没有将字符串列表绑定到ListView,而是将IEnumerable<String>绑定到TextBlock.Text字段,当它期望Stringthis.AInfoLv.Items.Add(new { Label=" " + string.Join(", ", abc.agentSkillsNameList), Value=" " + string.Join(", ", abc.agentSkillsLvlList) }); 时你可以在错误中看到。

解决问题的最快方法是将行更改为

<input type="text" onchange="newVar=this.value"/>