WPF 如何创建自定义tunelroutedevent?
我需要一个从父控件到子控件的隧道路由事件隧道的简单示例。
(这不是真实代码)——事实上,我越深入,我就越认为 XAML 是错误的——可能不应该在子节点上的 XAML 中注册隧道事件(不确定?)
<PARENT>
<MyControl DoSomethingOnUserAction="raiseTunnelEvent"> HELP </MyControl >
<CHILD> I SHOULD HANDLE tunnelled event </CHILD>
</PARENT>
简单、简洁的例子会很有帮助。
谢谢, 艾伦
I need a simple example of a Tunnel Routed Event tunnelling from a parent control to a child control.
(THIS IS NOT REAL CODE) -- in fact, the deeper I go, the more I think that the XAML is wrong -- probably should NOT sign up for the tunnelled event in XAML on the child node (not sure?)
<PARENT>
<MyControl DoSomethingOnUserAction="raiseTunnelEvent"> HELP </MyControl >
<CHILD> I SHOULD HANDLE tunnelled event </CHILD>
</PARENT>
Simple, concise example would be helpful.
Thanks,
Alan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定,但你可能想要一只猫吠叫。
Button 的 RoutedEvent ClickEvent(来自PresentationFramework)声明为:
请注意
Bubble
的readonly
RoutingStrategy
。以下内容可能有助于理解隧道、气泡和直接:
msdn.microsoft.com/en-us/library/system.windows.routingstrategy.aspx
这应该会引导您完成剩下的工作:
msdn.microsoft.com/en-us/magazine/cc785480.aspx
提示:按照惯例,WPF 中的隧道事件以“Preview”开头(例如“PreviewExplode”)。如果事件不以“Preview”开头,则可能不会不要使用隧道 RoutingStrategy。此外,您通常会看到隧道和气泡配对,隧道首先触发,然后是气泡,如“PreviewExplode”,然后是“Explode”。
如果您需要按钮的单击隧道,您可以考虑
Not sure, but you may be wanting a cat to bark.
The RoutedEvent ClickEvent of Button (from PresentationFramework) is declared as:
Note the
readonly
RoutingStrategy
ofBubble
.The following may help with understanding Tunnel, Bubble, and Direct:
msdn.microsoft.com/en-us/library/system.windows.routingstrategy.aspx
And this should take you the rest of the way:
msdn.microsoft.com/en-us/magazine/cc785480.aspx
A tip: by convention tunneling events in WPF begin with "Preview" (e.g.- "PreviewExplode". If the event doesn't begin with "Preview" it probably doesn't use the tunnel RoutingStrategy. Also you will usually see a Tunnel and Bubble paired with the Tunnel firing first then the Bubble as in "PreviewExplode" followed by "Explode".
If you need to have a Button's Click tunnel, you might consider
事实证明,《I have WPF In Action with Visual Studio 2008》一书(第 149 页)有一个非常具有误导性的图表,该图表似乎表明可以在父节点中引发 RoutedEvents,并且路由事件通过隧道传输到子节点。
事实证明并非如此... 1/2 天的糟糕图表被吹坏了(否则相当不错的书)[ ISBN : 1-933988-22-3 ]
Turns out the book I have WPF In Action with Visual Studio 2008, on page 149, has a very misleading diagram that seems to indicate that RoutedEvents can be raised in a parent node and that routed event tunnelled to child nodes.
That turns out to NOT be the case... 1/2 day blown b/c of bad diagram (fairly good book otherwise) [ ISBN : 1-933988-22-3 ]