Has it ever been possible to bind to a field in WPF?

时光总嘲笑我的痴心妄想 提交于 2020-01-21 12:26:08

问题


Someone suggested in another question that they, at some point, were able to bind a value to a field in WPF.

I know that this is not a supported scenario (and personally I have only seen binding work with properties), but is it even technically possible?


回答1:


No. Binding in WPF uses either a PropertyDescriptor or the Dependency Property mechanism, which only works on Properties.

(Technical note here: A Dependency Property is technically sort of a field - it's defined as a field, then registered with the DP system, though, and treated more like a property, so I would still call it a property... The field itself doesn't actually store the data in the case of a DP.)



来源:https://stackoverflow.com/questions/5387206/has-it-ever-been-possible-to-bind-to-a-field-in-wpf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!