As a best practice, manually convert your public fields to properties and implement your class using the INotifyPropertyChanged interface to raise the event change.
EDIT: Since you mentioned 100 fields, I suggest you reorganize your code, as in this wonderful answer: Tools for refactoring open C # fields in properties
Here is an example:
private string _customerNameValue = String.Empty; public string CustomerName { get { return this._customerNameValue; } set { if (value != this._customerNameValue) { this._customerNameValue = value; NotifyPropertyChanged(); } } } private void NotifyPropertyChanged([CallerMemberName] String propertyName = "") { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } }
Check this out: INotifyPropertyChanged Interface
Yair nevet
source share