wpf/silverlight 中的依赖属性与 javascript 对象属性
我最近在学习silverlight,发现很难理解依赖属性系统的本质。我可以将silverlight的依赖属性和javascript的对象属性进行类比吗?它们都是由类似哈希表的数据结构实现的,并且可以在运行时添加/删除,对吗?
i am learning silverlight recently and find its difficult to understand the essence of the dependency property system. can I make a analogy between silverlight's dependency property and javascript's object property? both of them are implemented by a hashtable-like data structure and can be add/remove at run time , am i right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你是不对的,WPF依赖属性不是动态的,对象有一组依赖属性,它们存储值的方式可能是相同的(我认为它更像是字典结构),但你不能只是动态地拥有一个新属性。但是,有一个名为附加属性的东西,它允许附加属性。
我建议您阅读我链接到的那些文章,它们应该很好地解释了一切。
You are not right, the WPF depdency properties are not dynamic, objects have a set of depedency properties the way they store values may be the same (i think it's more of a dictionary structure) but you cannot just have a new property on the fly. However there is something called attached properties which allows for additinal properties.
I would suggest you read those articles i linked to, they should explain everything quite well.
将 DependencyProperties 视为指针或地址。您不是将属性设置为值,而是将其设置为指向另一个值的地址。
例如,您不是说 TextBox 的文本等于 SomeValue,而是说它指向 ViewModel 中的字符串值。或者它指向某个对象的 Name 属性。或者指向指定的 ComboBox 的 SelectedText。当然,您总是可以说它直接指向“SomeValue”字符串。
基本上,它是一个依赖于其他值的属性。
Think of DependencyProperties as Pointers or Addresses. Instead of setting a property to a value, you are setting it to a an address which points to another value.
For example, instead of saying a TextBox's text is equal to SomeValue, you are saying it is pointing to a string value in the ViewModel. Or it is pointing to the Name property of some object. Or pointing to a specified ComboBox's SelectedText. Of course, you could always say it points directly to a string of "SomeValue"
Basically, it is a property that is dependent on some other value.