"Essential WPF - Chapter 7 Actions" 阅读笔记

Chapter 7 Actions

 

Up to now we have focused on the output side of the platform, looking at how an application is built up from controls that use visuals to display and layout to position everything.

 

Now we can start to look at the input side of the platform.

 

WPF Actions: events, commands, and triggers.

 

Action Principles: element composition, loose coupling, and declarative actions.

 

7.1 Action Principles

 

To allow actions to work with the way that WPF builds the display tree, with many elements that may be further composed of other elements, requires the use of element composition.

 

routed event 原来是来自于 element composition 引入的 event 处理难题

"Routed events are events that are designed to work well with a tree of elements ."

                                                                                        - "Important New Concepts in WPF "

 

7.2 Events

 

There are three types of routed events: direct, bubbling, and tunneling events.

 

Tunneling and bubbling work great for events that are built into every control, like mouse events; however, any event can tunnel or bubble.

To allow for both tunneling and bubbling, WPF supports attached events.

对 routing event 支持到了极致

 

Every event that uses the event system in WPF has a RoutedEvent field on the defining object, just like the Dependency-Property field that is used for the property system.

疑问, 这个方法好么?

 

7.3 Commands

 

简单点说, 就是一个通用的 Event Handler

Commands allow for a loose coupling between the UI and the behavior.

 

7.4 Triggers

 

Triggers are signaled by three things: (1) the state of a display property (Trigger), (2) the state of a data property (DataTrigger), or (3) an event (EventTrigger).

 

7.4.1 Adding Triggers to Data

Triggers can be used only inside of a template or style.

通过 Trigger 可以在绑定时做一些简单的检查, 设置属性工作, 从而赋予 XAML 一定的编程能力.

既然这样, 何不直接像 HTML, 引入 javascript 之类作为界面语言?

 

By using DataTrigger, we could move all the UI-dependent logic into the markup and leave the minimal amount of code in the code.

 

7.4.2 Adding Triggers to Controls

 

the design for Trigger and EventTrigger was inspired by the desire to have all view-dependent logic of a control declared in the markup.

 

7.4.3 Triggers as the New "if"

 

Triggers are a simple form of rules engine.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值