WPF 实现INotifyPropertyChanged .Net Framework 4.5

2021-02-20 08:20

阅读:411

标签:ber   void   自己   wpf   一个   ice   work   ram   pos   

  自己动手写了一个基类来实现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(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

标签:ber   void   自己   wpf   一个   ice   work   ram   pos   

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


评论


亲,登录后才可以留言!