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.
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); } }
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