什么是依赖属性的原因/场景像的DisplayMemberPath属性? [英] What are the reasons/scenarios for properties like DisplayMemberPath to be dependency properties?

查看:353
本文介绍了什么是依赖属性的原因/场景像的DisplayMemberPath属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能解释一下制作背后的理由说ItemsControl.DisplayMemberPath依赖属性,而不是只是一个普通的CLR属性?

Could anyone explain the reasoning behind making say ItemsControl.DisplayMemberPath a dependency property and not just a regular CLR property?

有没有这样的时候属性用于在数据绑定方案,款式,或其他依赖项属性相关的情况。任何真正的生活场景

Are there any real life scenarios when such properties are used in data binding scenarios, styles, or other dependency property related situations.

感谢。

更新:

原因这个问题就像

使你的财产的依赖   属性不总是必要或   适当的,将取决于你的   需要。有时,典型   支持你的财产的技巧   配备了私人领域就足够了。

Making your property a dependency property is not always necessary or appropriate and will depend on your needs. Sometimes, the typical technique of backing your property with a private field is adequate.

MSDN文档哪一种使它们没有什么清晰可辨的是一个依赖福利property.with私人领域是足够的依赖属性控制开发问题的声明。

in MSDN documentation which kind of make control developers question declarations of dependency properties which have no clearly identifiable benefits of being a dependency property.with a private field is adequate.

推荐答案

一致性:作为一个开发者,你不能假定没有人在那里需要一个特定的功能(在特定情况下) 。当我开发的自定义控制我一定要做出所有的公共属性DP的,你永远不知道别人使用该控件/属性可能有一个条件,它绑定或者用它的风格等的因此,最好是一致的;因为,如果某些控件的属性支持绑定,造型等等。我希望其他属性,以支持他们。

Consistency: As a developer you can't assume that no one out there would require a particular feature(in a particular case). When I develop any custom control I make sure to make all public properties DP's as you never know someone using that control/property may have a requirement to bind it or use it in style etc. So it is better to be consistent; as, if some of controls properties support Binding, styling etc. I expect other properties to support them too.

我也遇到这个问题很多与像同步融合3'rd方控制;在许多场合,我们所提出的门票要价绑定不同的控制属性的支持。正如这个问题:

I have faced this issue a lot with 3'rd party controls like Sync-fusion; On numerous occasions we had raised tickets asking for Binding support for various control properties. As mentioned in this question:

<一个href="http://stackoverflow.com/questions/2572101/why-do-so-many-wpf-controls-implement-clr-properties-instead-of-dependency-proper">Why这么多WPF控件实现依赖属性的CLR性能呢?

可以有一个特殊的原因,有此属性为DP,但总的来说,我还没有遇到任何财产(WPF控件),这是不是一个DP;和多数民众真正有用的,你可以设计的UI(使用绑定,造型等),而无需和检查每一个和所有控件的每个属性。

There can be a particular reason for having this property as DP but in general I haven't come across any property(WPF Controls) which is not a DP; and thats really useful, you can design UI(using Binding, styling etc.) without going and checking each and every property of all controls.

这篇关于什么是依赖属性的原因/场景像的DisplayMemberPath属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆