如何在DisplayMemberPath中显示此内容 所以我要说我有财产
public IEnumerable<KeyValuePair<string, string>> Defaults{ get { return defaults; } }
在QuestionFile类中的,我想把它放在下面的ListBox
中<ListBox ItemsSource="QuestionsFile.Defaults" DisplayMemberPath="?"/>
答案 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
属性值)