1

How do you show this in DisplayMemberPath so let's say I have the property

public IEnumerable<KeyValuePair<string, string>> Defaults{ get { return defaults; } }

in the class QuestionsFile and I want to put this in the following ListBox

<ListBox ItemsSource="QuestionsFile.Defaults" DisplayMemberPath="?"/>
abatishchev
  • 98,240
  • 88
  • 296
  • 433
Stef Dhollander
  • 91
  • 1
  • 1
  • 3
  • What exactly do you want to display? The key and the value? Why aren't you just using a POCO with two properties which are named appropriately for the object your KeyValuePair represents? – BenCr Mar 31 '11 at 11:42
  • It's just the value which I want to show.. but I'll will do It like that – Stef Dhollander Mar 31 '11 at 11:48

2 Answers2

1

You should set the DisplayMemberPath to Key or Value :

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

and assign ItemSource in code behind :

lst.ItemsSource = Defaults; 

or in xaml :

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

Sources :

Community
  • 1
  • 1
mathieu
  • 30,974
  • 4
  • 64
  • 90
0
<ListBox ItemsSource="QuestionsFile.Defaults" DisplayMemberPath="?"/>

Do you mean this?

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

(Assuming thisCtl is the x:Name property value for the QuestionFile control)

Kieren Johnstone
  • 41,277
  • 16
  • 94
  • 144