There is a class consisting of a set of view properties.
public SomeType Property1 { get; set; } I can not edit this class, but I really want to follow the changes in its properties. How do I do this in real time?
There is a class consisting of a set of view properties.
public SomeType Property1 { get; set; } I can not edit this class, but I really want to follow the changes in its properties. How do I do this in real time?
Inherit your class from it and either override the property, or if it is sealed, create your property.
class myClass : ParentClass { public SomeType myProperty1 { get{return base.Property1;} set{ base.Property1=value; onmyProperty1Changed(); } } public event EventHandler myProperty1Changed; public void onmyProperty1Changed() { if(myProperty1Changed!= null) myProperty1Changed(this,null); } } You can like that
TypeDescriptor.GetProperties(typeof(SomeClass))[nameof(theSomeClass.Prop1)].AddValueChanged(theSomeClass, eventHandler); In short, we obtain a PropertyDescriptionCollection for the type SomeClass , select its property Prop1, and add a handler to change it, specifying the instance of the desired class as the first parameter.
There is only one problem, I have not yet figured out how to use one handler for all properties, because EventArgs has no parameters for the event.
Source: https://ru.stackoverflow.com/questions/506526/
All Articles