C # - How to determine if a property is changing

I need to know if the public property (which has getter and setter) has been changed. The property is in a simple class (without a user control / component, etc.).
Is there an elegant way to subscribe to some event that notifies when a property changes?
I tried to understand what microsoft is doing in the Binding object (using a reflector), and this made me learn the PropertyDescriptor.AddValueChanged method, but that did not work for me. maybe it only works for components / user controls ...

Any suggestions?

Thanks,
Adi barda

+4
source share
2 answers

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

This is a fairly well-known interface used by middleware APIs. Just follow the implementation example on this msdn page.

+12
source

INotifyPropertyChanged should work, but you can also just create your own event specific to this property, without dragging it to system.componentmodel.

+2
source

Source: https://habr.com/ru/post/1300891/


All Articles