问题

在开发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的更多相关文章

  1. WPF:数据绑定--PropertyChangeNotification属性更改通知

      PropertyChangeNotification属性更改通知 实现效果:1.拍卖金额自动随属性值变化而通知界面绑定的值变化. 关键词 : INotifyPropertyChanged Obse ...

  2. 【WPF学习笔记】之WPF基础:依赖关系属性和通知

    这些天来,对象似乎已经忙得晕头转向了.每个人都希望它们做这做那.Windows® Presentation Foundation (WPF) 应用程序中的典型对象会接到各种各样不同的请求:有要求绑定到 ...

  3. WPF 中双向绑定通知机制之ObservableCollection使用

    msdn中   ObservableCollection<T> 类    表示一个动态数据集合,在添加项.移除项或刷新整个列表时,此集合将提供通知. 在许多情况下,所使用的数据是对象的集合 ...

  4. WPF 普通属性变化通知

    问题描述:使用ObservableCollection<OrderItem> source 给Datagrid.ItemsSource赋值,在后台更新source集合后,前台Datagri ...

  5. wpf 属性变更通知接口 INotifyPropertyChanged

    在wpf中将控件绑定到对象的属性时, 当对象的属性发生改变时必须通知控件作出相应的改变, 所以此对象需要实现 INotifyPropertyChanged 接口 例: //实现属性变更通知接口 INo ...

  6. WCF X.b 操作引用了已经从 Y.b 操作导出的消息元素 [http://tempuri.org/:b]。可以通过更改方法名称或使用 OperationContractAttribute 的 Name 属性更改其中一个操作的名称...

    详细错误如下: 很可能由 IncludeExceptionDetailInFaults=true 创建的 ExceptionDetail,其值为: System.InvalidOperationExc ...

  7. JavaScript通知浏览器,更改通知数目

    http://lab.ejci.net/favico.js/ http://www.zhangxinxu.com/study/201607/web-notifications.html http:// ...

  8. SVN更改通知的工具commitmonitor

    SVN更改通知的工具commitmonitor 下载地址: https://sourceforge.net/projects/commitmonitor/files/latest/download 工 ...

  9. WPF:向客户端发出某一属性值已更改的通知INotifyPropertyChanged接口

    Person.cs using System.ComponentModel; namespace _01_INotifyPropertyChanged { class Person:INotifyPr ...

随机推荐

  1. php 过滤js字符串代码

    $str = '<script type="text/javascript" src="dd.js"></script> 测试php正则 ...

  2. 访问sharepoint站点自动使用当前用户名和密码登录

    https://blog.csdn.net/zw_2011/article/details/7417123 1.把sharepoint站点添入可信站点.   点击菜单栏“工具”——〉“Internet ...

  3. [Compose] 16. Apply multiple functors as arguments to a function (Applicatives)

    We find a couple of DOM nodes that may or may not exist and run a calculation on the page height usi ...

  4. [RxJS] Use RxJS concatMap to map and concat high order observables

    Like switchMap and mergeMap, concatMap is a shortcut for map() followed by a concatAll(). In this le ...

  5. js进阶 11-13 jquery如何包裹元素和去除元素外的包裹

    js进阶 11-13  jquery如何包裹元素和去除元素外的包裹 一.总结 一句话总结:wrap().wrapAll().unwrap().innerWrap()四个方法 1.jquery中unwr ...

  6. Nginx+uswgi+Django部署

    详情参考: http://blog.csdn.net/a_little_snail/article/details/78045636

  7. SWIFT学习笔记04

    1.在实际编译时,Swift 编译器会优化字符串的使用.使实际的复制仅仅发生在绝对必要的情况下,这意味着您将字符串作为值类型的同一时候能够获得极高的性能. 2.for character in &qu ...

  8. sqlplus中登陆账户用@加上数据库sid

    sqlplus连接数据库时除了先输入用户名再输入密码的方式还有一种直接输入方式,而且使用@sid区分数据库,在有多个数据库时可方便区分 connect sys/sysdb@oraclesid as s ...

  9. 【BZOJ 1014】 [JSOI2008]火星人prefix

    [题目链接]:http://www.lydsy.com/JudgeOnline/problem.php?id=1014 [题意] 让你在线查询最长公共前缀. 支持单节点修改; 插入操作; [题解] / ...

  10. 【p093】细胞分裂

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] Hanks博士是BT(Bio-Tech,生物技术)领域的知名专家.现在,他正在为一个细胞实验做准备工作 ...