欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

wpf ComboBox绑定Dictionary数据源

程序员文章站 2022-06-07 18:36:06
...

UI界面代码

<ComboBox Height="23" Name="cbHingeAvoidance" Width="250" />

后台代码

Dictionary<int, string> HingeAvoidancedic = new Dictionary<int, string>();
HingeAvoidancedic.Add(1, "铰链避让板件");
HingeAvoidancedic.Add(2, "板件避让铰链");
HingeAvoidancedic.Add(3, "产品内缩避让");
cbHingeAvoidance.SelectedValuePath = "Key";
cbHingeAvoidance.DisplayMemberPath = "Value";
cbHingeAvoidance.ItemsSource = HingeAvoidancedic;
cbHingeAvoidance.SelectedValue = 1;

界面显示效果

wpf ComboBox绑定Dictionary数据源