博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
数据绑定(五)使用集合对象作为列表控件的ItemsSource
阅读量:7218 次
发布时间:2019-06-29

本文共 1053 字,大约阅读时间需要 3 分钟。

原文:

ItemsSource属性可以接收一个IEnumerable接口派生类的实例作为自己的值,ItemsSource里存放的是一条一条的数据,列表式控件的条目容器会为这些数据传上外衣,只要为ItemsControl对象设置了ItemsSource属性值,ItemsControl对象就会自动迭代其中的数据元素,为每一个数据元素准备一个条目容器,并使用Binding在条目容器与数据元素之间建立起关联,例子:

界面代码:

后台代码:

public MainWindow()        {            InitializeComponent();            List
stuList = new List
() { new Student(){Id=0, Name="daijun", Age=11}, new Student(){Id=1, Name="Tim", Age=12}, new Student(){Id=2, Name="Tom", Age=13}, new Student(){Id=3, Name="Kyle", Age=14}, new Student(){Id=4, Name="Tony", Age=15} }; listBoxStudents.ItemsSource = stuList; listBoxStudents.DisplayMemberPath = "Name"; Binding binding = new Binding(); binding.Source = listBoxStudents; binding.Path = new PropertyPath("SelectedItem.Id"); textBox1.SetBinding(TextBox.TextProperty, binding); }

转载地址:http://khxym.baihongyu.com/

你可能感兴趣的文章
Java中File类如何扫描磁盘所有文件包括子目录及子目录文件
查看>>
VC++ 限制窗口的大小范围的方法
查看>>
结对开发-返回一个整数数组中最大子数组的和(首尾相接版)
查看>>
meanshift-聚类
查看>>
不要if else的编程
查看>>
rn.ShowDialog() == DialogResult.OK
查看>>
20160519
查看>>
SCU 3132(博弈)
查看>>
正则表达式
查看>>
delete archivelog all 无法彻底删除归档日志?
查看>>
Redis五大数据类型
查看>>
大型分布式网站架构技术总结
查看>>
矩阵求导与投影梯度相关问题
查看>>
SVN
查看>>
C语言编程写的一个http下载程序(王德仙)2012-04-08
查看>>
CCF201409-3 字符串匹配(100分)
查看>>
UVALive2203 UVa10042 Smith Numbers【质因数分解+素数判定+数位之和】
查看>>
Project Euler Problem 9: Special Pythagorean triplet
查看>>
HDU5701 中位数计数【中位数】
查看>>
Python 深浅拷贝 (Shallow copy and Deep copy in Python)
查看>>