标签:
效果如下:
故以键值对来定义一个类,如:
public class CategoryInfo { public string Name { get; set;} public string Value{ get; set;} }
List<CategoryInfo> categoryList = new List<CategoryInfo>(); categoryList.Add(new CategoryInfo{Name="English", Value="en_US"});//英语 categoryList.Add(new CategoryInfo{Name="中文", Value="zh_CN"});//中文 categoryList.Add(new CategoryInfo{Name="日本語", Value="ja_JP"});//日语
comboType.ItemsSource = categoryList; //这里的Name和Value不能乱填哦 comboType.DisplayMemberPath = "Name";//显示出来的值 comboType.SelectedValuePath = "Value";//实际选中后获取的结果的值
private void Button_Click(object sender, RoutedEventArgs e) { //如显示的是English,这里的SelectedValue的值就是en_US string langName = cbLang.SelectedValue.ToString(); }
标签:
原文地址:http://www.cnblogs.com/tommy-huang/p/4613803.html