1.使用ListBox绑定Dictionary字典数据

ListBox常用事件SelectionChanged

private void bindListBox()
{
Dictionary<string, string> dic = new Dictionary<string, string>();
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<string, string> item = (KeyValuePair<string, string>)e.AddedItems[];
}

Xaml

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="57*"/>
<RowDefinition Height="347*"/>
</Grid.RowDefinitions>
<ListBox x:Name="listBox" Grid.Row="1" SelectionChanged="listBox_SelectionChanged" />
<Label x:Name="label" Content="系统字体显示" FontWeight="Bold" Foreground="Red" HorizontalAlignment="Left" Margin="36,22,0,0" VerticalAlignment="Top" Height="26" Width="97"/>
</Grid>

2.使用字典集合单项绑定,ListBox.ItemTemplete模板

后台同上

Xaml定义:

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="21*"/>
<RowDefinition Height="248*"/>
</Grid.RowDefinitions>
<ListBox x:Name="listBox" Grid.Row="1">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Background="LightBlue" Content="{Binding Path=Key,Mode=OneWay}"/>
<TextBox Grid.Column="1" Text="{Binding Path=Value,Mode=OneWay}"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>

显示结果:

Wpf控件ListBox使用实例2

Wpf ListBox数据绑定实例1--绑定字典集合的更多相关文章

  1. WPF ListBox数据绑定

    本文来源 http://wshoufeng1989.blog.163.com/blog/static/202047033201282911633670/  风随影动的博客 使用数据库AllData , ...

  2. WPF TreeView绑定字典集合

    <TreeView Name="Tree" HorizontalAlignment="Left" Height="269" Width ...

  3. WPF绑定到集合

    什么是集合视图? 集合视图是位于绑定源集合顶部的一层,您可以通过它使用排序.筛选和分组查询来导航和显示源集合,而无需更改基础源集合本身.集合视图还维护着一个指向集合中的当前项的指针.如果源集合实现了 ...

  4. WPF之数据绑定

    WPF学习之数据绑定 1. Banding基础 WPF中的数据绑定提供了很强大的功能.与普通的WinForm程序相比,其绑定功能为我们提供了很多便利,例如Binding对象的自动通知/刷新,Conve ...

  5. WPF:数据绑定总结(1) https://segmentfault.com/a/1190000012981745

    WPF:数据绑定总结(1) visual-studio c# 1.3k 次阅读  ·  读完需要 16 分钟 0 一.概念:什么是数据绑定? WPF中的数据绑定:是在应用程序 UI 与业务逻辑之间建立 ...

  6. WPF双向数据绑定总结

    参考官方:https://docs.microsoft.com/zh-cn/dotnet/framework/wpf/data/data-binding-wpf 实例程序:https://files. ...

  7. [No000012E]WPF(6/7):概念绑定

    WPF 的体系结构,标记扩展,依赖属性,逻辑树/可视化树,布局,转换等.今天,我们将讨论 WPF 最重要的一部分——绑定.WPF 带来了优秀的数据绑定方式,可以让我们绑定数据对象,这样每次对象发生更改 ...

  8. CPF 入门教程 - 数据绑定和命令绑定(二)

    CPF netcore跨平台UI框架 系列教程 CPF 入门教程(一) CPF 入门教程 - 数据绑定和命令绑定(二) 数据绑定和Wpf类似,支持双向绑定.数据绑定和命令绑定是UI和业务逻辑分离的基础 ...

  9. 在Winform开发框架中下拉列表绑定字典以及使用缓存提高界面显示速度

    在我们开发Winform界面的时候,往往需要绑定数据字典操作,也就是绑定一些下拉列表或者一些列表显示等,以便我们方便选择数据操作,常见的字典绑定操作就是对下拉列表的处理,本篇随笔是基于DevExpre ...

随机推荐

  1. runAllManagedModulesForAllRequests 和 invalid url

    有这样的经验, 在本地的 IIS 上网站运行正常,但是发布到服务器上就一堆怪怪的问题 : MVC routing not work http://stackoverflow.com/questions ...

  2. cf D. Physical Education and Buns

    http://codeforces.com/contest/394/problem/D 题意:给你n个数,然后通过操作使得这n个数变为一个等差数列,操作是可以经过小于等于k次加1或减去1,要使得k尽量 ...

  3. 硬盘IO,SAS,SATA,和HD TUNE

    SAS的接口技术可以向下兼容SATA.具体来说,二者的兼容性主要体现在物理层和协议层的兼容. SAS系统的背板(Backplane)既可以连接具有双端口.高性能的SAS驱动器,也可以连接高容量.低成本 ...

  4. 模拟I2C从机

    模拟I2C主机的比较多,但是从机相对主机而言要难很多,这个供大家借鉴. 这个从机程序支持主机对它的随机写和随机读,连续读和连续写没做,有兴趣的可以完善下,呵呵. //Microcontrol CODE ...

  5. scheme和common lisp 区别

    Scheme and Common Lisp use different names for some of the basic system functions. Many Lisp program ...

  6. Javascript面向对象编程(三):非构造函数的继承 by 阮一峰

    今天是最后一个部分,介绍不使用构造函数实现"继承". 一.什么是"非构造函数"的继承? 比如,现在有一个对象,叫做"中国人". var Ch ...

  7. 数学:UVAoj 11174 Stand in a Line

    Problem J Stand in a Line Input: Standard Input Output: Standard Output All the people in the bytela ...

  8. 树状数组(二维):COGS 1532 [IOI2001]移动电话

    1532. [IOI2001]移动电话 ★☆   输入文件:mobilephones.in   输出文件:mobilephones.out   简单对比 时间限制:5 s   内存限制:256 MB ...

  9. 数据结构:HDU 2993 MAX Average Problem

    MAX Average Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  10. 我的第一个wp8小程序

    一:截图,功能介绍:点击音乐红色按钮,播放铃声 二:代码 XAML代码 <phone:PhoneApplicationPage x:Class="PhoneApp1.MainPage& ...