Wpf ListBox数据绑定实例1--绑定字典集合
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数据绑定实例1--绑定字典集合的更多相关文章
- WPF ListBox数据绑定
本文来源 http://wshoufeng1989.blog.163.com/blog/static/202047033201282911633670/ 风随影动的博客 使用数据库AllData , ...
- WPF TreeView绑定字典集合
<TreeView Name="Tree" HorizontalAlignment="Left" Height="269" Width ...
- WPF绑定到集合
什么是集合视图? 集合视图是位于绑定源集合顶部的一层,您可以通过它使用排序.筛选和分组查询来导航和显示源集合,而无需更改基础源集合本身.集合视图还维护着一个指向集合中的当前项的指针.如果源集合实现了 ...
- WPF之数据绑定
WPF学习之数据绑定 1. Banding基础 WPF中的数据绑定提供了很强大的功能.与普通的WinForm程序相比,其绑定功能为我们提供了很多便利,例如Binding对象的自动通知/刷新,Conve ...
- WPF:数据绑定总结(1) https://segmentfault.com/a/1190000012981745
WPF:数据绑定总结(1) visual-studio c# 1.3k 次阅读 · 读完需要 16 分钟 0 一.概念:什么是数据绑定? WPF中的数据绑定:是在应用程序 UI 与业务逻辑之间建立 ...
- WPF双向数据绑定总结
参考官方:https://docs.microsoft.com/zh-cn/dotnet/framework/wpf/data/data-binding-wpf 实例程序:https://files. ...
- [No000012E]WPF(6/7):概念绑定
WPF 的体系结构,标记扩展,依赖属性,逻辑树/可视化树,布局,转换等.今天,我们将讨论 WPF 最重要的一部分——绑定.WPF 带来了优秀的数据绑定方式,可以让我们绑定数据对象,这样每次对象发生更改 ...
- CPF 入门教程 - 数据绑定和命令绑定(二)
CPF netcore跨平台UI框架 系列教程 CPF 入门教程(一) CPF 入门教程 - 数据绑定和命令绑定(二) 数据绑定和Wpf类似,支持双向绑定.数据绑定和命令绑定是UI和业务逻辑分离的基础 ...
- 在Winform开发框架中下拉列表绑定字典以及使用缓存提高界面显示速度
在我们开发Winform界面的时候,往往需要绑定数据字典操作,也就是绑定一些下拉列表或者一些列表显示等,以便我们方便选择数据操作,常见的字典绑定操作就是对下拉列表的处理,本篇随笔是基于DevExpre ...
随机推荐
- Github博客地址
欢迎访问我的Github博客: J.R.Smith_blog
- ubuntu 解压rar
Ubuntu下解压rar文件的方法 一般通过默认安装的ubuntu是不能解压rar文件的,只有在安装了rar解压工具之后,才可以解压.其实在ubuntu下安装rar解压工具是非常简单的,只需要两个步骤 ...
- 温习H3C S5500的VLAN配置
这,才是我想要的... ACCESS还是TRUNK TYPE?
- splay模板
点操作: splay树可以一个一个的插入结点,这样的splay树是有序树,结点权值大于左儿子小于右儿子 这样就是点操作 区间操作: 还有就是可以自己建树,这样的splay树就不是按权值的有序树,它不满 ...
- Redis Sentinel实现Failover
redis版本:2.8.17 服务器规划: 10.50.13.34(6379 master) 10.50.13.35(6379 slave) 10.50.13.36(6379 slave) 10. ...
- 【转】Android JNI编程—JNI基础
原文网址:http://www.jianshu.com/p/aba734d5b5cd 最近看到了很多关于热补的开源项目——Depoxed(阿里).AnFix(阿里).DynamicAPK(携程)等,它 ...
- 数据结构(堆):POJ 1442 Black Box
Black Box Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10658 Accepted: 4390 Descri ...
- C# dll玩注入!.net运行时库内置!?
Contents Introduction Back To Fundamentals Load The CLR Fundamentals Advanced DLL Injection Fundamen ...
- Codeforces Round #260 (Div. 1) --B. A Lot of Games (Trie)
B. A Lot of Games Andrew, Fedor and Alex are inventive guys. Now they invent the game with strings f ...
- POJ 2057 The Lost House
题意:一只蜗牛,它的房子在树上的某个叶子节点上,它要从树的根节点出发,寻找自己的房子.树的任意两个节点的距离为1,房子出现在每个叶子节点上的可能性一样.有的节点上有虫子,如果有虫子,虫子会告诉蜗牛它的 ...