简体   繁体   English

类内的属性更改事件

[英]Property Changed event within class

I got a question about events within classes. 我有一个关于班级内事件的问题。

I have a whole load of properties within my class and want to fire an event whenever a property is changed. 我的类中有大量的属性,并且每当属性更改时都想触发一个事件。 I want to use the changed properties to calculate a result. 我想使用更改后的属性来计算结果。

One possible option might be adding a call to every single property-set but this is - for my understanding - too q'n'd. 一种可能的选择是向每个单个属性集添加调用,但是-就我所知-也是如此。

The common approach to realise this would be to implement the INotitfyPropertyChanged interface and raise the PropertyChanged event in every settter method for the properties where you need it. 实现此目的的常用方法是实现INotitfyPropertyChanged接口,并在每个settter方法中针对需要的属性引发PropertyChanged事件。

Then you implement an event handler which reacts to the event and performs the operations needed. 然后,您实现一个事件处理程序,该事件处理程序对事件做出反应并执行所需的操作。

https://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged(v=vs.110).aspx https://msdn.microsoft.com/zh-CN/library/system.componentmodel.inotifypropertychanged(v=vs.110).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM