1.使用ListBox绑定Dictionary字典数据
ListBox常用事件SelectionChanged
private void bindListBox(){ Dictionarydic = new Dictionary (); foreach (var item in Fonts.SystemFontFamilies.OrderBy(q => q.Source)) { dic.Add(item.Source, "---->" + string.Join(",", item.FamilyNames.Select(q => q.ToString()))); //dic.Add(item.Source,"------"); } listBox.ItemsSource = dic;}//选中结果事件private void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e){ ListBox thisBox = e.Source as ListBox; //e.AddedItems 所有选中的结果 //e.RemovedItems 所有未选中的结果 //解析结果是 Key Value键值对 KeyValuePair item = (KeyValuePair )e.AddedItems[0];}
Xaml
2.使用字典集合单项绑定,ListBox.ItemTemplete模板
后台同上
Xaml定义:
显示结果: