differerence between RoutedEventHandler and EventHandler

本文详细解释了在用户界面元素树中,路由事件如何不论是否被处理都会进行冒泡传播。通过一个具体例子展示了当点击内层控件时,如单选按钮,该点击事件不仅会被内层控件捕获,还会传递给外层包含控件进行处理。
A routed event bubbles up through the element tree whether it is handled or not, a normal event does not。
 
A routed event is is bubbled up the user interface tree whether or not it is handled by the object that receives the event. For example, if we return to a previous example in which we had a button within which were three sub-controls, the middle of which was a stack panel containing a  check box whose content had another stack panel with two buttons, the first of which itself had content which was an html button…
differerence between RoutedEventHandler and EventHandler - picacure - picacure的博客 
you can see that we want to be able to click on the radio button within the check box that is within the button and yet still have the click event bubble up and click the button. Yet, at the same time, we may want to respond to the click on the radio button or the check box being clicked. We saw the XAML for creating this control previously so there is no need to review that. It will be unchanged except that  we'll want to add just one control for this example, and that is a list box that can hold messages indicating which control has registered the mouse down event,
differerence between RoutedEventHandler and EventHandler - picacure - picacure的博客 
Note that to accommodate this helpful list box we need to add a row and a column to the grid, which is easily accomplished in our row and grid definitions at the top of the file,
differerence between RoutedEventHandler and EventHandler - picacure - picacure的博客 
With that in place, we need only create event handlers to see how the events "bubble up" even as they are handled. 
differerence between RoutedEventHandler and EventHandler - picacure - picacure的博客 
Each of these event handlers is implemented to add a notice to the list box we added in the third column,
differerence between RoutedEventHandler and EventHandler - picacure - picacure的博客 
If you click on an outer object (such as the check box border, only one event fires,
differerence between RoutedEventHandler and EventHandler - picacure - picacure的博客 
Whereas if you click on an inner object (e.g., a radio button, you can see that the event is routed to the outer (containing) objects for handling as well.
differerence between RoutedEventHandler and EventHandler - picacure - picacure的博客 
In this image, the user has clicked on the inner radio button. Because MouseLeftDown is a routed event, the event bubbles up through the UI tree, from the radio button to the check box to the surrounding border (and on up through the other surrounding UI elements that don't have event handlers!)

转载于:https://www.cnblogs.com/jiangC/archive/2010/07/31/2769171.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值