C# 将哈希表绑定到WPF组合框
请告诉我如何将哈希表绑定到WPF组合框。我在WPF Combobox类中找不到DisplayMember、ValueMember属性 请给我一些建议 问候,,C# 将哈希表绑定到WPF组合框,c#,wpf,combobox,hashtable,C#,Wpf,Combobox,Hashtable,请告诉我如何将哈希表绑定到WPF组合框。我在WPF Combobox类中找不到DisplayMember、ValueMember属性 请给我一些建议 问候,, 约翰。这很直截了当。这里有一个例子 main window.xaml <Window ...> <StackPanel> <ComboBox ItemsSource="{Binding MyHashTable}" SelectedValuePath=
约翰。这很直截了当。这里有一个例子 main window.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;
}
}
公共部分类主窗口:窗口
{
公共字典MyHashTable
{
得到;
设置
}
公共主窗口()
{
初始化组件();
MyHashTable=新字典();
添加(“键1”、“值1”);
添加(“键2”、“值2”);
添加(“键3”、“值3”);
添加(“键4”、“值4”);
this.DataContext=this;
}
}
谢谢Meleak,我会试试的。