4est
4est

Reputation: 3168

Bind value to ComboBox from dictionary

I have a list:

public SortedDictionary<string, string> ProjectDictionaryList { get; internal set; }

Now I want to bind the value to ComboBox:

ComboBox DockPanel.Dock="Right" ItemsSource="{Binding Path=ProjectDictionaryList}" 
         IsSynchronizedWithCurrentItem="True" Style="{StaticResource myCombo}" 
         SelectedItem="{Binding SelectedProject}"

But how to bind ProjectDictionaryList.Value?

Upvotes: 0

Views: 138

Answers (2)

Avinash Reddy
Avinash Reddy

Reputation: 937

You can use DisplayMemberPath="" to display the Values in combobox or if you don't want to do that ProjectDictionaryList.Values can be binded with the help of {Binding Path=}

Upvotes: 0

Clemens
Clemens

Reputation: 128070

Set DisplayMemberPath and SelectedValuePath and bind SelectedValue to select a dictionary entry by its key:

<ComboBox
    ItemsSource="{Binding ProjectDictionaryList}" 
    DisplayMemberPath="Value"
    SelectedValuePath="Key"
    SelectedValue="{Binding SelectedProject}"/>

Upvotes: 3

Related Questions