Is there a way to detect changes in a field or property without using INotifyPropertyChanged?
My point is to connect, for example, to some field and detect that its value has changed, even if it was an int field.
Is there a way to detect changes in a field or property without using INotifyPropertyChanged?
My point is to connect, for example, to some field and detect that its value has changed, even if it was an int field.
There is no effect you could use while writing an integer other than the one you wrote yourself. There is no way around INotifyPropertyChanged.
You can wrap the field with a property that raises the event. You can have a manager class that exposes a property and through which you manage that field even when the field is not part of that class. You could poll the value with a thread and if it changes raise the event.
The sane approach in most cases is to follow the mvvm blueprint as close as possible so no one is too surprised down the road.
You can decide to throw a customized event when a property changed. The only thing your upper layers have to do is subscribe to the SomeProperty event. You can replace the EventHandler delegate to something that suits your needs.
public event EventHandler SomePropertychanged; private int _SomeProperty; public int SomeProperty { get { return this._SomeProperty; } set { if (this._SomeProperty != value) SomePropertychanged?.Invoke(this, new EventArgs()); } }