将相同的EventHandler添加到所有UIElements [英] Adding the same EventHandler to all UIElements

查看:62
本文介绍了将相同的EventHandler添加到所有UIElements的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
有没有一种简单的方法可以将事件处理程序添加到所有UI元素?
我希望窗口中的每个UIElement都具有相同的MouseRightButtonDown事件和相同的事件处理程序.

问候

Hello,
is there an easy way of adding an Event Handler to all UI Elements?
I want every UIElement in my Window to have the same MouseRightButtonDown event with the same Event Handler.

greets

推荐答案



是的,这是可能的.您可以通过在Window中遍历所有UIElement并为其分配事件处理程序来以编程方式进行设置.

虽然,您可能希望查看事件的TunnelDown和BubblingUp(称为事件路由)-这可能会简化您的工作.

WPF:入门指南:第3部分n [ ^ ]

http://msdn.microsoft.com/en-us/library/ms754010.aspx [ ^ ]
Hi,

Yes it''s possible. You could programmatically set it by looping through all UIElements in the Window and assigning an event handler it.

Although, you might want to look at TunnelDown and BubblingUp of events (Called event routing) - this might simplify your work.

WPF: A Beginner''s guide: Part 3 of n[^]

http://msdn.microsoft.com/en-us/library/ms754010.aspx[^]


这篇关于将相同的EventHandler添加到所有UIElements的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆