views:

24

answers:

3

Hi!

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!

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; 
A: 

Shouldn't you just comment out the base.OnMouseWheel(e); part, so the normal behaviour doesn't get executed?

Peter Kiers
Thank you on your help, but I already tried to do that, with no luck..ScrollViewer again use mouse wheel...
rjovic
Think you should just move up in your visual tree and find the ScrollViewer and set the IsEnabled property to false.
Peter Kiers
I can't because I use scrollviewer to pan around content after I zoom it...
rjovic
A: 

Try to set:

e.Handled=true;
VyvIT
A: 

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

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

rjovic