首页 > Windows开发 > 详细

WPF 实现INotifyPropertyChanged .Net Framework 4.5

时间:2018-01-15 19:47:18      阅读:216      评论:0      收藏:0      [点我收藏+]

  自己动手写了一个基类来实现INotifyPropertyChanged接口,以后可以直接使用。

       

 1 using System.ComponentModel;
 2 using System.Runtime.CompilerServices;
 3 
 4 public abstract class NotifyPropertyBase: INotifyPropertyChanged
 5 {
 6      public event PropertyChangedEventHandler PropertyChenged;
 7 
 8      protected void SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
 9      {
10           if (object.Equals(storage, value)) return;
11           storage = value;
12           this.OnPropertyChanged(propertyName);
13      }
14 
15      protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
16     {
17         if (this.PropertyChanged != null)
18             {
19                    this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
20              }
21     }
22 }

 

WPF 实现INotifyPropertyChanged .Net Framework 4.5

原文:https://www.cnblogs.com/Johar/p/8289405.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!