Have On_property_Changed events also deliver the old value with special signature
See original GitHub issueThe On_property_Changed
is very useful when adding property changed watchers when a property has changed.
Unfortunately the same mechanism cannot be used to unregister the previous delegate attached to the previous object.
It would be nice if we could either extend On_property_Changed
so that when given with a signature such as:
void OnNameChanged(string oldValue)
it would provide the old value as well so we could undo whatever was done to that property before.
Probably it would need to be a nullable to also support value types.
Example:
class A {
public SomeOtherClass Classy { get; set;}
private OnClassyChanged(SomeOtherClass old){
if (old != null) {
old.PropertyChanged -= WatchChanges;
}
if (Classy != null) {
Classy.PropertyChanged += WatchChanges;
}
}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
c# - Handling OnPropertyChanged
The event handler provided, has to have the signature of the PropertyChangedEventHandler delegate. This signature is:
Read more >Proposal: Add OldValue and NewValue properties in ...
PropertyChanged event of a model from another view model, e.g. logging of property changes of the model from the view model. Current ...
Read more >DependencyPropertyChangedEv...
This delegate is the handler signature for particular events that report dependency property changes. An event that uses this handler is exposed as...
Read more >Event-Driven Programming :: K-State CIS 400 Textbook
To do so, we need both a name for the event, and a delegate. In C# a Delegate, a special type that represents...
Read more >Attached Properties - What Are They Good For? - Code Mill Matt
An attached property is a special type of bindable property, ... it's signature receives the view it is attached to – the old...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I had this in my “private backlog” for quite a while, but now found some to look at this.
Hmm, yes the code currently requires
object
parameters. I don’t know why, from a quick glance at the code it doesn’t seem this would be too hard to change, but I may be wrong.