如何防止ScrollViewer使用MouseWheel事件 [英] How to prevent ScrollViewer from using MouseWheel event

查看:199
本文介绍了如何防止ScrollViewer使用MouseWheel事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建用于缩放布局的SL应用程序.一切工作正常,除了当我使用鼠标滚轮放大时,在某些缩放滚动条开始使用鼠标滚轮之后,之后我才可以滚动而不进行缩放.如果将滚动条放在结尾或开头,则只能再次缩放.如何防止scrollviewer使用鼠标滚轮?我希望只能通过滚轮操作缩放.预先谢谢你!

I'm building SL application for zooming and panning across the layout. Everything is working fine, except that when I zoom in using mouse wheel , after some zoom scrollbars start to use mouse wheel so after that I can scroll not zoom. I only can zoom again if I put scrollbars at the end or begining. How to prevent scrollviewer from using mouse wheel? I want that zoom only be operated by wheel. Thank you in advance!

这是我缩放内容时的MouseWheel方法的代码:

Here is my code of MouseWheel method when I'm zooming content :

protected override void OnMouseWheel(MouseWheelEventArgs e) 
    { 
        base.OnMouseWheel(e);             

        if (e.Delta > 0) 
        { 
            this.aniScaleX.To += 0.2; 
            this.aniScaleY.To += 0.2; 

            this.sbScale.Begin(); 
        } 
        else if (e.Delta < 0 && (this.aniScaleX.To > 1 && this.aniScaleY.To > 1)) 
        { 
            this.aniScaleX.To -= 0.2; 
            this.aniScaleY.To -= 0.2; 

            this.sbScale.Begin(); 
        } 

        Sizer.Width = Board.ActualWidth * (double)this.aniScaleX.To; 
        Sizer.Height = Board.ActualHeight * (double)this.aniScaleY.To; 

推荐答案

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..

这篇关于如何防止ScrollViewer使用MouseWheel事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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