属性更改通知(INotifyPropertyChanged)——针对ObservableCollection
问题
在开发webform中,wpf中的ObservableCollection,MSDN中说,在添加项,移除项时此集合通知控件,我们知道对一个集合的操作是CURD
但是Update的时候没有提供集合通知,也就是说当我Update的时候,虽然"集合内容“已被修改,但是"控件“却没有实现同步更新
即ObservableCollection,ObservableCollection类实现了INotifyPropertyChanged,所以集合“新增”、“修改”会通知,而“修改”,需要T实现INotifyPropertyChanged接口
方案1:INotifyPropertyChanged
传统方式,实现接口INotifyPropertyChanged
public class StudentByINotifyPropertyChanged: INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
//实现INotifyPropertyChanged接口
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
private string sex;
private string name;
public string Sex
{
get { return sex; }
set
{
sex = value;
NotifyPropertyChanged("Sex");
}
}
public string Name
{
get { return name; }
set
{
name = value;
NotifyPropertyChanged("Name");
}
}
}
示例代码
https://github.com/zLulus/NotePractice/tree/dev3/WPF/WpfDemo/PropertyChanged
方案2:采用框架实现好的
mvvmlight的ViewModelBase已实现该方法,使用如下

List与ObservableCollection对比
List可检查更改,不能检查增加、删除
ObservableCollection检查增加、删除,不能检查更改
属性更改通知(INotifyPropertyChanged)——针对ObservableCollection的更多相关文章
- WPF:数据绑定--PropertyChangeNotification属性更改通知
PropertyChangeNotification属性更改通知 实现效果:1.拍卖金额自动随属性值变化而通知界面绑定的值变化. 关键词 : INotifyPropertyChanged Obse ...
- 【WPF学习笔记】之WPF基础:依赖关系属性和通知
这些天来,对象似乎已经忙得晕头转向了.每个人都希望它们做这做那.Windows® Presentation Foundation (WPF) 应用程序中的典型对象会接到各种各样不同的请求:有要求绑定到 ...
- WPF 中双向绑定通知机制之ObservableCollection使用
msdn中 ObservableCollection<T> 类 表示一个动态数据集合,在添加项.移除项或刷新整个列表时,此集合将提供通知. 在许多情况下,所使用的数据是对象的集合 ...
- WPF 普通属性变化通知
问题描述:使用ObservableCollection<OrderItem> source 给Datagrid.ItemsSource赋值,在后台更新source集合后,前台Datagri ...
- wpf 属性变更通知接口 INotifyPropertyChanged
在wpf中将控件绑定到对象的属性时, 当对象的属性发生改变时必须通知控件作出相应的改变, 所以此对象需要实现 INotifyPropertyChanged 接口 例: //实现属性变更通知接口 INo ...
- WCF X.b 操作引用了已经从 Y.b 操作导出的消息元素 [http://tempuri.org/:b]。可以通过更改方法名称或使用 OperationContractAttribute 的 Name 属性更改其中一个操作的名称...
详细错误如下: 很可能由 IncludeExceptionDetailInFaults=true 创建的 ExceptionDetail,其值为: System.InvalidOperationExc ...
- JavaScript通知浏览器,更改通知数目
http://lab.ejci.net/favico.js/ http://www.zhangxinxu.com/study/201607/web-notifications.html http:// ...
- SVN更改通知的工具commitmonitor
SVN更改通知的工具commitmonitor 下载地址: https://sourceforge.net/projects/commitmonitor/files/latest/download 工 ...
- WPF:向客户端发出某一属性值已更改的通知INotifyPropertyChanged接口
Person.cs using System.ComponentModel; namespace _01_INotifyPropertyChanged { class Person:INotifyPr ...
随机推荐
- java开发中序列化与反序列化起到的作用
基本概念: 序列化是将对象状态转换为可保持或传输的格式的过程.与序列化相对的是反序列化,它将流转换为对象. 这两个过程结合起来,能够轻松地存储和数据传输. 特别在网络传输中,它的作用显得尤为重要.我们 ...
- 【53.90】【BZOJ 3875】 [Ahoi2014]骑士游戏
Time Limit: 30 Sec Memory Limit: 256 MB Submit: 564 Solved: 304 [Submit][Status][Discuss] Descriptio ...
- mount新磁盘
fdisk -l mkfs.xfs /dev/xvdb mkdir /data mount /dev/xvdb /data df -h vi /etc/fstab /dev/xvdb /data ...
- Go语言学习(十)bytes包处理字节切片
bytes包提供了对字节切片进行读写操作的一系列函数 字节切片处理的函数比較多,分为基本处理函数,比較函数,后缀检查函数,索引函数,切割函数, 大写和小写处理函数和子切片处理函数等. 1.字节切片基本 ...
- [NPM] Create a bash script to replace a complex npm script
In this lesson we will look at pulling out complex npm scripts into their own external bash scripts. ...
- ssh和SSH服务(包含隧道内容)
ssh和SSH服务(包含隧道内容) 72.16.10.6:/etc/fstab-->/172.16.10.3:/tmp/a.txt. [root@xuexi ~]# scp 172.16.10. ...
- python 使用顺序表实现栈和队列
栈: # -*- coding: utf-8 -*- # @author: Tele # @Time : 2019/04/24 下午 2:33 # 采用list(顺序表)实现栈结构,后入先出 clas ...
- Erlang/OTP 中文手册
http://erldoc.com/ Open Telecom Platform application array asn1rt base64 binary calendar code dbg di ...
- SpringBoot JPA 专题
Error: Error starting ApplicationContext. To display the auto-configuration report re-run your appli ...
- HDU 1422 重温世界杯 - 贪心
传送门 题目大意: 给一串数,又正有负,求每一个前缀都大于0的最长子串长度. 题目分析: 直接贪心:每次左端点向右推1,不断延伸右端点,更新答案. code #include<bits/stdc ...