/ / Viazanie Hashtable na WPF Combobox - c #, wpf, combobox, hashtable

Väzba Hashtable na WPF Combobox - c #, wpf, combobox, hashtable

Prosím, povedz mi, ako môžem viazať hashtable na WPF Combobox. Nemôžem nájsť vlastnosti DisplayMember, ValueMember v triede WPF Combobox.

Prosím, radu.

S pozdravom, John.

odpovede:

3 pre odpoveď č. 1

Je to celkom priamočiara. Tu je príklad

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;
}
}