Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# - How to determine whether a property is changed

I need to know whether a public property (which has getter & setter) is changed. The property is in a simple class (no user control/component etc).
Is there an elegant way to subscribe to some kind of event which notifies when property is changed?
I tried to see what microsoft is doing in their Binding object (using reflector) and that lead me to explore the PropertyDescriptor.AddValueChanged method but it didn't worked for me. maybe it works only for components/user controls...

Any suggestions?

Thanks,
Adi Barda

like image 749
Adi Barda Avatar asked Dec 10 '22 17:12

Adi Barda


1 Answers

Just implement the INotifyPropertyChanged interface:
http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx

This is a pretty well known interface, which is used by the binding APIs. Just follow the example implementation on that msdn page.

like image 103
Joel Martinez Avatar answered Dec 25 '22 22:12

Joel Martinez