wpf/silverlight 中的依赖属性与 javascript 对象属性

发布于 2024-11-16 22:45:23 字数 119 浏览 3 评论 0原文

我最近在学习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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

相思故 2024-11-23 22:45:23

你是不对的,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.

自由如风 2024-11-23 22:45:23

将 DependencyProperties 视为指针或地址。您不是将属性设置为值,而是将其设置为指向另一个值的地址。

例如,您不是说 TextBox 的文本等于 SomeValue,而是说它指向 ViewModel 中的字符串值。或者它指向某个对象的 Name 属性。或者指向指定的 ComboBox 的 SelectedText。当然,您总是可以说它直接指向“SomeValue”字符串。

<TextBox Text="{Binding SomeProperty}" />
<TextBox Text="{Binding SomeObject.SomeProperty}" />
<TextBox Text="{Binding ElementName=MyComboBox, Path=SelectedText}" />
<TextBox Text="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"

<TextBox Text="{Binding SomeProperty}" />
<TextBox Text="{Binding SomeObject.SomeProperty}" />
<TextBox Text="{Binding ElementName=MyComboBox, Path=SelectedText}" />
<TextBox Text="SomeValue" />

Basically, it is a property that is dependent on some other value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文