问题描述
我有一个Control
,它继承自WinForms中的NumericUpDown
.
I have a Control
which inherits from NumericUpDown
in WinForms.
我想处理对NumericUpDown
的DecimalPlaces
属性的更改,因此我都尝试过声明
I want to handle changes to the DecimalPlaces
-Property of NumericUpDown
, therefore I have both tried declaring a
void OnDecimalPlacesChanged()
{
MessageBox.Show("Moeeep");
}
,并在ctor中手动订阅PropertyChanged
-event
.当我更新DecimalPlaces
并且不知道为什么时,它似乎没有触发.
and also manually subscribing the PropertyChanged
-event
in the ctor manually. It seems to just not fire when I update DecimalPlaces
and I have no idea why.
推荐答案
由于Control
不实现INotifyPropertyChanged
,因此只有您的类可以实现.因此,DecimalPlaces
更改时,Control
不会引发任何事件.没有框架可以将其注入其代码中.
Since Control
does not implement INotifyPropertyChanged
, only your class does. Because of that, the Control
doesn't raise any event when the DecimalPlaces
changes. No framework can inject that into their code.
就目前而言,最好的方法是重写UpdateEditText
方法. DecimalPlaces
属性更改时将调用它.请注意,这当然不是调用该方法的唯一原因,因此您在那里可能会遇到问题...
For now, the best thing you have is to override the UpdateEditText
method. It is called when the DecimalPlaces
property changes. Note that this is of course not the only reason the method is called, so you might have a problem there...
这篇关于Fody.PropertyChanged不会在继承的Property上触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!