Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将哈希表绑定到WPF组合框_C#_Wpf_Combobox_Hashtable - Fatal编程技术网

C# 将哈希表绑定到WPF组合框

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=

请告诉我如何将哈希表绑定到WPF组合框。我在WPF Combobox类中找不到DisplayMember、ValueMember属性

请给我一些建议

问候,,
约翰。

这很直截了当。这里有一个例子

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,我会试试的。