views:

177

answers:

2

Hi Guys,
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

+11  A: 

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.

Joel Martinez
+2  A: 

INotifyPropertyChanged should work but you could also just create your own event that is specific to the property without dragging in system.componentmodel.

Kevin Gale