Simple small INotifyPropertyChanged implementation

后端 未结 6 1524
深忆病人
深忆病人 2021-01-06 07:51

Say I have the following class:

public MainFormViewModel
{
    public String StatusText {get; set;}
}

What is the easiest smallest way to g

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-06 08:10

    Have a go of this http://code.google.com/p/notifypropertyweaver/

    All you need to do is implement INotifyPropertyChanged

    So your code will look like

    public MainFormViewModel : INotifyPropertyChanged
    {
        public String StatusText {get; set;}
    
        #region INotifyPropertyChanged Implementation
    }
    

    The build task will compile this (you never see the below code)

    public MainFormViewModel : INotifyPropertyChanged
    {
        public String StatusText {get; set;}
        private string statusText;
    
        public string StatusText 
        {
           get { return statusText; }
           set
           {
               if (value!= statusText)
               {
                   statusText = value;
                   OnPropertyChanged("StatusText");
               }
           }
        }
    
        #region INotifyPropertyChanged Implementation
    }
    

提交回复
热议问题