當前位置:成語大全網 - 新華字典 - 在wpf中怎麽綁定comboBox的值

在wpf中怎麽綁定comboBox的值

前臺:

<ComboBox Name="combobox" Width="120" Height="30"/>

後臺:

public test5()

{

InitializeComponent();

Dictionary<int, string> mydic = new Dictionary<int, string>()

{

{1,"a"},

{2,"b"},

{3,"c"}

};

combobox.ItemsSource = mydic;

combobox.SelectedValuePath = "Key";

combobox.DisplayMemberPath = "Value";

}

ItemsSource 指定comboBox的數據源,可以是字典,list等任何形式的數據集合

SelectedValuePath 表示每個item的的實際值,DisplayMemberPath 表示每個item的顯示值