/ / Прив'язка Hashtable до WPF Combobox - c #, wpf, combobox, hashtable

Binding Hashtable для WPF Combobox - c #, wpf, combobox, hashtable

Скажіть, будь ласка, як я можу прив'язати хеш-таблицю до WPF Combobox. Я не можу знайти властивості DisplayMember, ValueMember у класі WPF Combobox.

Будь ласка, порадь.

З повагою, Джон.

Відповіді:

3 для відповіді № 1

Це досить прямо. Ось приклад

MainWindow.xaml

<Window ...>
<StackPanel>
<ComboBox ItemsSource="{Binding MyHashTable}"
SelectedValuePath="Key"
DisplayMemberPath="Value"/>
</StackPanel>
</Window>

MainWindow.xaml.cs

public partial class MainWindow : Window
{
public Dictionary<string, string> MyHashTable
{
get;
set;
}
public MainWindow()
{
InitializeComponent();
MyHashTable = new Dictionary<string, string>();
MyHashTable.Add("Key 1", "Value 1");
MyHashTable.Add("Key 2", "Value 2");
MyHashTable.Add("Key 3", "Value 3");
MyHashTable.Add("Key 4", "Value 4");
this.DataContext = this;
}
}