Silverlight (WPF) - 理解Attached Property
来源:互联网 发布:js 正则 身份证号 编辑:程序博客网 时间:2024/05/17 22:58
Attached Property Overview中提到了三种典型的Attach Property的应用模型:
How Attached Properties Are Used by the Owning Type
Although attached properties are settable on any object, that does not automatically mean that setting the property will produce a tangible result, or that the value will ever be used by another object. Generally, attached properties are intended so that objects coming from a wide variety of possible class hierarchies or logical relationships can each report common information to the owning type. The type that defines the attached property for Silverlight typically follows one of these models:
1. The type that defines the attached property is designed so that it can be the parent element of the elements that will set values for the attached property. The type then iterates its child elements through internal logic, obtains the values, and acts on those values in some manner.
2. The type that defines the attached property will be used as the child element for a variety of possible parent elements and content models.
3. The attached property reports information to a service.
第一种就是最常见的用于界面布局的attach property,例如Canvas.Top, DockPanel.Dock等
第二种暂没有遇到
第三种没具体解释,不好理解。Nathan的blog提到,这种情况其实就是Attached Service 或者叫 Attached Behavior。可以理解为,就是把一些attached property的owner中的逻辑attach到其他对象中去。ToolTipService.ToolTip就是一个最直观的例子。Nathan还给了一个链接,也是一个很简单明了的Attached Service的例子,将鼠标右键及其事件处理逻辑抽象为一个Attached Service,可attach到其他任何适用的对象中去。
BenCon给出了另外一个attached service的例子,他称之为Ramora Pattern (应该是Remora, 一种有吸盘的鱼,用来比喻attached service 可以吸附到其他对象上)
总结一下两个例子,Attached Service是利用了PropertyChangedCallback回调函数来注册目标对象(被attached的对象)上的某个事件,并处理事件来实现其附加逻辑的。
Nick的2005年的一篇老文,讲述了Attached Property的设计思路由来。
- Silverlight (WPF) - 理解Attached Property
- Silverlight - Attached Behavior + Command
- WPF的Attached属性
- Customized Attached Property 附加属性
- silverlight wpf
- WPF+silverlight
- Wpf 附加属性(Attached Properties)
- Attached Property在Xaml中,使用Property Element的写法
- WPF之Denpendence Property
- Dependency property in WPF
- WPF Property属性
- @property理解
- WPF和Silverlight 二
- WPF/Silverlight中的Command
- WPF/Silverlight 属性解释
- Silverlight、WPF环境配置
- wpf/silverlight文章推荐
- WPF/Silverlight中的Command
- 开个博客
- openjweb平台配置cas server单点登录
- Perl using Arrays
- Oracle时间日期操作
- 列出用户A的所有进程
- Silverlight (WPF) - 理解Attached Property
- 马云经典语录:
- 创建自己的ActionContext对象简化开发
- Perl using Hashes
- 牛根生经典语录
- 对数据库的基本操作
- 史玉柱经典语录
- 区域寻路算法---改善服务器上的怪物寻路
- 公司创业板上市与普通员工有关?