在scrollviewer wpf中禁用鼠标滚轮滚动 [英] disable mouse wheel scrolling in scrollviewer wpf

查看:1285
本文介绍了在scrollviewer wpf中禁用鼠标滚轮滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在xaml代码中

<StackPanel>
 <ScrollViewer>
  <local:CustomCanvas>
  </local:CustomCanvas>
 </ScrollViewer>
</StackPanel>

CustomCanvs具有放大/缩小功能.但是,当我在CustomCanvas区域中旋转鼠标滚轮时,ScrollViewer的滚动条有效,而放大/缩小无效.当我滚动ScrollViewer的滚动条时,不仅CustomCanvas的放大/缩小工作而且ScrollViewer的滚动工作都很好.

CustomCanvs has a zoom in/out function. But when I spin the mouse wheel in the CustomCanvas area, ScrollViewer's scrollbar works and zoom in/out don't work. And when I scroll the scrollbar of the ScrollViewer, not only CustomCanvas' zoom in/out work but also scrolling of the ScrollViewer work well.

当我旋转鼠标滚轮时,我只想放大/缩小.而且,当我滚动滚动条时,我只想滚动即可工作.

When I spin the mouse wheel, I want only zoom in/out. And when I scroll the scrollbar, I want only scrolling to work.

如何防止ScrollViewer的鼠标滚轮事件使鼠标滚轮旋转? 以及如何防止ScrollViewer滚动条的滚动放大/缩小? 请帮助

How I can prevent mouse wheel event of ScrollViewer from spining mouse wheel? And how I can prevent zoom in/out from scrolling of ScrollViewer's scrollbar? Please help

推荐答案

您可以处理自定义Canvas的MouseWheel事件,以便当鼠标指向画布区域并且滑移事件被指责时,您可以设置MouseWheelEventArgs的Handled属性变为真实:

you could handle the MouseWheel Event of Custom Canvas so that when the mouse is pointed in your canvas area and the wheeling event accured you set the Handled property of the MouseWheelEventArgs to true :

 private void UIElement_OnMouseWheel(object sender, MouseWheelEventArgs e)
    {
        e.Handled = true;
        //handler your zoomIn/Out here
    }

和Xaml

<StackPanel>
 <ScrollViewer>
  <local:CustomCanvas  MouseWheel="UIElement_OnMouseWheel">
  </local:CustomCanvas>
 </ScrollViewer>
</StackPanel>

这篇关于在scrollviewer wpf中禁用鼠标滚轮滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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