IEnumerable的<keyvaluepair <字符串,字符串>&GT;在DisplayMemberPath中</keyvaluepair <string,string>

时间:2011-03-31 11:34:25

标签: c# .net xaml listbox ienumerable

如何在DisplayMemberPath中显示此内容 所以我要说我有财产

public IEnumerable<KeyValuePair<string, string>> Defaults{ get { return defaults; } }
在QuestionFile类中的

,我想把它放在下面的ListBox

<ListBox ItemsSource="QuestionsFile.Defaults" DisplayMemberPath="?"/>

2 个答案:

答案 0 :(得分:1)

您应该将DisplayMemberPath设置为Key或Value:

<ListBox x:Name="lst" DisplayMemberPath="Value"/>

并在后面的代码中分配ItemSource:

lst.ItemsSource = Defaults; 

或在xaml:

<ListBox ItemsSource="{Binding Defaults, RelativeSource={RelativeSource FindAncestor, AncestorType=Window}}" x:Name="lst" DisplayMemberPath="Value"/>

来源:

答案 1 :(得分:0)

<ListBox ItemsSource="QuestionsFile.Defaults" DisplayMemberPath="?"/>

你是说这个吗?

<ListBox ItemsSource="{Binding Path=Defaults,ElementName=thisCtl}" DisplayMemberPath="?"/>

(假设thisCtl是QuestionFile控件的x:Name属性值)