INotifyPropertyChanged 和自动属性 [英] INotifyPropertyChanged and Auto-Properties
问题描述
有没有办法将 INotifyPropertyChanged
与自动属性一起使用?也许是一个属性或其他东西,对我来说并不明显.
Is there a way to use INotifyPropertyChanged
with auto-properties? Maybe an attribute or something other, not obvious to me.
public string Demo{
get;set;
}
对我来说,自动属性将是一件非常实用的事情,但几乎总是,如果属性值已更改并且没有执行此操作的机制,我必须引发 PropertyChanged
事件,自动属性对我没用.
For me, auto-properties would be an extremely practicall thing, but almost always, I have to raise the PropertyChanged
-event if the property value has been changed and without a mechanism to do this, auto-properties are useless for me.
推荐答案
没有内置机制来执行此操作.像 PostSharp 之类的东西可能会为你添加这样的东西(或 Mark Gravell 的 HyperDescriptor,如果您只是对让此数据绑定感知感兴趣).
There's no built-in mechanism to do this. Something like PostSharp would likely be able to add something like this for you (or Mark Gravell's HyperDescriptor, if you're just interested in making this databinding-aware).
这篇关于INotifyPropertyChanged 和自动属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!