Use INotifyPropertyChanged monitor attribute changes

Sometimes we need asynchronously monitor changes in object properties, and make the appropriate treatment according to the change. It can be simple to achieve this goal will be achieved by way of monitoring class INotifyPropertyChanged interface.

ContractedBlock.gif ExpandedBlockStart.gif Code
public class  monitored categories: the INotifyPropertyChanged { // event is declared public Event  PropertyChangedEventHandler the PropertyChanged; // defines a method for triggering an event Private void  NotifyPropertyChanged ( String  info)   { IF (the PropertyChanged  =! Null ) { // trigger event       the PropertyChanged ( the this new new  PropertyChangedEventArgs (info));     }   } // method when the property set, call the trigger event public String  Property1 { the SET  { IF 

  

   
  

   

    
 
      




  

   
    

      
(value  ! = the this ._property1) {NotifyPropertyChanged ( " info " );}     }   } } public class  monitor class { // define an event processing method static void  DoItWhenPropertyChanged ( Object  SENDER, PropertyChangedEventArgs E) {} public static void  the Main ( String [ ] args) { // add event processing method of     monitored objects .PropertyChanged  + = new new  PropertyChangedEventHandler (DoItWhenPropertyChanged);   } } 




 
  

   
  
  
    


        


Reproduced in: https: //www.cnblogs.com/crossingdawn/archive/2009/07/01/1514785.html

Guess you like

Origin blog.csdn.net/weixin_34248258/article/details/93409833