Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

scroll - disable mouse wheel scrolling in scrollviewer wpf

In xaml code

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

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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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
    }

and in the Xaml

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...