WPF 绑定集合 根据集合个数改变样式 INotifyCollectionChanged
2015-09-14 11:33
791 查看
问题:当前ListBox Items 绑定 集合数据源ListA时候;ListA集合数据源中存在另外一个集合ListB,当更改或往ListB集合中添加数据的时候,通知改变?
实体类继承 INotifyCollectionChanged 即可实现:
BaseViewModel:
View Code
完美解决!!
https://social.msdn.microsoft.com/Forums/vstudio/zh-CN/1b55492b-e9ca-4610-a40d-107d64c8ea9f/inotifycollectionchanged-on-listt
实体类继承 INotifyCollectionChanged 即可实现:
BaseViewModel:
public class ViewModel : BaseViewModel { private List<Person> _lp = null; private RelayCommand _addCommand, _removeCommand; public ViewModel() { LP = new List<Person>(); LP.Add(new Person(1, "aaa")); LP.Add(new Person(2, "bbb")); } public List<Person> LP { get { return _lp; } set { _lp = value; } } public ICommand AddCommand { get { if (_addCommand == null) { _addCommand = new RelayCommand(param => this.Add(), param => this.CanAdd); } return _addCommand; } } public bool CanAdd { get { return true; } } public void Add() { Person ps = new Person(3, "ccc"); LP.Add(ps); CollectionChanged += new NotifyCollectionChangedEventHandler(List_CollectionChanged); OnPropertyChanged("LP"); OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, LP[0], 0)); } public ICommand RemoveCommand { get { if (_removeCommand == null) { _removeCommand = new RelayCommand(param => this.Remove(), param => this.CanRemove); } return _removeCommand; } } public bool CanRemove { get { return true; } } public void Remove() { LP.RemoveAt(0); CollectionChanged += new NotifyCollectionChangedEventHandler(List_CollectionChanged); OnPropertyChanged("LP"); OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, LP[0], 0)); } private void List_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { // ?????????? } }
View Code
完美解决!!
https://social.msdn.microsoft.com/Forums/vstudio/zh-CN/1b55492b-e9ca-4610-a40d-107d64c8ea9f/inotifycollectionchanged-on-listt
相关文章推荐
- 十天学会DIV+CSS(DIV布局)
- css margin
- CSS实现的灰色下拉菜单效果代码
- css 图片垂直居中总结
- CSS实例:用fieldset、legend实现文字写在边线上的效果
- CSS3选择器(二)
- CSS字体中英文名称对照表:如宋体对应SimSun
- 如果删除行内样式中某一个 属性
- animate.css – 齐全的CSS3动画库
- 百度前端笔试题目--css 实现一个带尖角的正方形
- CSS学习笔记——CSS选择器样式总结
- word 文档结构图 字体样式改变,保证有用
- css3实现条纹背景
- CSS居中
- 基于CSS3实现的黑色个性导航菜单效果
- css3常用属性
- JS+CSS实现的简单折叠展开多级菜单效果
- JS+CSS简单树形菜单实现方法
- 深入了解css的行高Line Height属性
- css