8

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

1 Answer 1

7

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>
1
  • Thankyou. I already did that. I have child Image and TextBlock in CustomCanvas. Only if i spin mouse wheel on the child of CustomCanvas, it work... Why MouseWheel event not accure in other area of CustomCanvas except of child area? In other area, wheel event accure for ScrollViewer so scroll work.
    – Lightstar
    Commented Dec 19, 2014 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.