RoutedEventArgs与EventArgs [英] RoutedEventArgs vs EventArgs
问题描述
RoutedEventArgs
超过 EventArgs
;虽然它并没有说明为什么。 我有一个赢取表单应用程序,使用widgets的接口,试图不绑定到特定的显示技术(在Presenters / ViewModels),所以如果我的IButton Click事件现在需要采取 RoutedEventArgs
现在我猜这是没有用的。
有人可以解释一下,如果我应该切换到所有情况下的 RoutedEventArgs
,为什么?
除此之外,还有其他人在使用界面小部件时有其他的经验/观点吗?
一个 RoutedEvent
通过 Logical
树,从源元素到根元素( Bubble
事件路由),或者从根元素到子级别元素( Tunnel
事件路由)不太频繁。这意味着如果您在 StackPanel
内部有一个 Button
,那么它本身就在网格
;如果您在控件中定义单击
事件,它们将触发它们,除非其中一个处理。
如果事件路由是 Bubble
(命名为常规事件单击
),它将会:
按钮 - > StackPanel - >网格
如果事件路由是隧道
(命名为预览点击
),它将以其他方式:
网格 - > StackPanel - >按钮
所以现在使用处理,这很简单。如果它是一个 Bubble
路由,而 Button
设置 RoutedEventArgs.Handled
为true,那么 StackPanel
和 Grid
将不会触发它。与 RoutedEvent
相同,如果 Grid
处理它,则 StackPanel
和 Button
不会触发它。
这是我的理解,简而言之,我避免了一些东西简单。
我推荐本章,以便更好地了解此WPF功能。 >
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.
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.
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?
Well, basically a RoutedEvent
travels through the Logical
tree, either from the source element to root element (Bubble
event route) or, less frequently from root element to sub levels elements (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:
Button -> StackPanel -> Grid
If the event route is Tunnel
(named PreviewClick
), it will go the other way around:
Grid -> StackPanel -> Button
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.
I recommend this chapter for better understanding of this WPF feature.
这篇关于RoutedEventArgs与EventArgs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!