问题

在开发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. ios开发多线程四:NSOperation多图下载综合案例

    #import "ViewController.h" #import "XMGAPP.h" @interface ViewController () /** t ...

  2. iOS开发Quzrtz2D 十:圆形图片的绘制以及加边框圆形图片的绘制

    一:圆形图片的绘制 @interface ViewController () @property (weak, nonatomic) IBOutlet UIImageView *imageV; @en ...

  3. JavaScript 初学者应知的 24 条最佳实践

    原文:24 JavaScript Best Practices for Beginners (注:阅读原文的时候没有注意发布日期,觉得不错就翻译了,翻译到 JSON.parse 那一节觉得有点不对路才 ...

  4. 【30.49%】【codeforces 569A】Music

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【u223】放牙刷

    [题目链接]: [题解] 错排公式 f[n] = (n-1)*(f[n-1]+f[n-2]); 这样理解: 要从n-1和n-2递推到n; 假设第n个位置上的数要放在前n-1个位置中的k位置;则有n-1 ...

  6. 记录一次mysql由5.6升级到5.7出现的异常---Expression #23 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'c.commentCount' which is not functionally dependent on columns in GROUP BY clause;

    ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expre ...

  7. Ntp配置文件详解

    1. http://www.ine.com/resources/ntp-authentication.htm 2. http://blog.chinaunix.net/uid-773723-id-16 ...

  8. HDU 5072 Coprime (单色三角形+容斥原理)

    题目链接:Coprime pid=5072"> 题面: Coprime Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: ...

  9. [React Router v4] Style a Link that is Active with NavLink

    We often need to be able to apply style to navigation links based on the current route. In React Rou ...

  10. php如何实现万年历的开发(每日一课真是非常有效率)

    php如何实现万年历的开发(每日一课真是非常有效率) 一.总结 一句话总结: 1.判断每月有多少天: 通过data函数来判断,$days=date('t',$firstday); 2.判断每月的第一天 ...