我学习WPF / Silverlight和在MS vidcast看到它现在推荐使用 RoutedEventArgs
在 EventArgs的
;虽然它没有透露具体原因。
I am learning WPF / Silverlight and saw in an MS vidcast that it is now recommended to use RoutedEventArgs
over EventArgs
; although it didn't say exactly why.
我有一个双赢窗体应用程序使用的小工具界面,企图以不依赖于特定的显示技术(以presenters /的ViewModels),所以如果我的iButton点击事件,现在需要采取 RoutedEventArgs
现在,我想这是不是有用。
I have a win forms app that uses interfaces for "widgets" in an attempt to not be tied to a specific display technology (in Presenters / ViewModels), so if my IButton Click event now needs to take the RoutedEventArgs
now I guess it isn't as useful.
有人可以解释,如果我应该切换到 RoutedEventArgs
在所有情况下,为什么?
Can someone please explain if I should switch to RoutedEventArgs
in all cases and why?
顺便说一句,没有任何人有经验/关于使用界面部件为我描述他们的意见?
As an aside, does anyone else have experience / opinions about using interface widgets as I'm describing them?
好了,基本上一个 RoutedEvent
穿过逻辑
树,无论是从顶部到底部(泡泡
事件路由)或底部到顶部(隧道
事件路由)。这意味着,如果你有一个按钮
内部的的StackPanel
,这本身就是一个电网;如果你定义了一个点击
事件中,他们都将触发它的控制,除非其中一人的手柄的吧。
Well, basically a RoutedEvent
travels through the Logical
tree, either from top to bottom (Bubble
event route) or bottom to top (Tunnel
event route). What this means is that if you have a Button
inside of a StackPanel
, that itself is inside of a Grid
; if you define a Click
event in the controls they will all trigger it unless one of them handles it.
如果该事件的路线是泡泡
(命名为定期举行的活动点击
),它会:
If the event route is Bubble
(named as a regular event Click
), it will go:
按钮 - > StackPanel中 - >电网
如果该事件的路线是隧道
(名为 previewClick
),它会去周围的其他方法
If the event route is Tunnel
(named PreviewClick
), it will go the other way around:
格 - > StackPanel中 - >按钮
所以,现在用的处理的,它是pretty的简单。如果它是一个泡泡
路线和按钮
设置 RoutedEventArgs.Handled
为true,的StackPanel
和电网
将不会触发它。同样的,在 RoutedEvent
,如果电网
处理它,在的StackPanel
和按钮
将不会触发它。
So now with the handling, it's pretty simple. If it's a Bubble
route and the Button
sets the RoutedEventArgs.Handled
to true, that StackPanel
and Grid
will not trigger it. Same with the RoutedEvent
, if the Grid
handles it, the StackPanel
and Button
will not trigger it.
这是我概括地说理解,我回避了一些工具和简易性。
This is my understanding in a nutshell, I avoided some stuff for simplicity.
我推荐this章为了更好地理解这个WPF功能。
I recommend this chapter for better understanding of this WPF feature.