且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何防止ScrollViewer使用MouseWheel事件

更新时间:2023-12-01 23:03:10

MouseWheel事件正在冒泡 活动.这意味着如果多个 MouseWheel事件处理程序是 注册了一系列对象 由亲子相连 在对象树中的关系 每个人都可能接收到事件 在那种关系中反对.这 冒泡的隐喻表明 事件从源头开始并且有效 在对象树上的位置.为一个 冒泡事件,发件人可用 到事件处理程序识别 处理事件的对象,而不是 必然是那个实际上的对象 收到输入条件 发起了活动.获取对象 发起了该事件,请使用 事件的原始来源值 数据. http://msdn.microsoft .com/en-us/library/system.windows.uielement.mousewheel(VS.95).aspx

The MouseWheel event is a bubbling event. This means that if multiple MouseWheel event handlers are registered for a sequence of objects connected by parent-child relationships in the object tree, the event is potentially received by each object in that relationship. The bubbling metaphor indicates that the event starts at the source and works its way up the object tree. For a bubbling event, the sender available to the event handler identifies the object where the event is handled, not necessarily the object that actually received the input condition that initiated the event. To get the object that initiated the event, use the OriginalSource value of the event data. http://msdn.microsoft.com/en-us/library/system.windows.uielement.mousewheel(VS.95).aspx

在我的情况下,ScrollViewer总是在收到事件之前,因为他位于视觉树的顶部.因此,我只是在scrollviewer中在鼠标滚轮事件上注册了事件处理程序,并且总是在发生该事件时,将其重定向到我的原始"鼠标滚轮函数即可进行缩放.

In my case,ScrollViewer always received event before because he is on the top of the visual tree. So I just registered event handler in scrollviewer on mouse wheel event and always when It happens, I simply redirect him to my "original" mousewheel function which do zoom.

我希望这样可以帮助在这里像我一样被卡住"的人.谢谢大家的回答和建议.

I hope so that this will help somebody who is "stuck" like me here. Thank you all on your answers and suggestions..