I want to bind my combo box ItemsSourse to the "value" i.e. (string component) of the
ObservableCollection<KeyValuePair<object, string>>.
How can I do that?
I want to bind my combo box ItemsSourse to the "value" i.e. (string component) of the
ObservableCollection<KeyValuePair<object, string>>.
How can I do that?
You could bind the ItemsSource to the ObservableCollection and then set the DisplayMemberPath to Value:
<ComboBox ItemsSource="{Binding YourCollection}" DisplayMemberPath="Value" />
The values in the combo box will then match the Values from the KeyValuePairs.
The easiest way to go would be to use the DisplayMemberPath
property:
<ComboBox ItemsSource="{Binding Pairs}" DisplayMemberPath="Value" />
Alternatively, you could expose a new property in your viewmodel that will only contain the values. For example:
public ObservableCollection<string> AllValues { get; set; }
public ViewModel()
{
AllValues = new ObservableCollection<string>(Pairs.Select(x => x.Value));
}
<ComboBox ItemsSource="{Binding AllValues}" />