Fody.PropertyChanged不会在继承的Property上触发 [英] Fody.PropertyChanged doesn't fire on inherited Property

查看:275
本文介绍了Fody.PropertyChanged不会在继承的Property上触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Control,它继承自WinForms中的NumericUpDown.

I have a Control which inherits from NumericUpDown in WinForms.

我想处理对NumericUpDownDecimalPlaces属性的更改,因此我都尝试过声明

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上触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆