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;
Try to set:
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..
This took me awhile (WPF), but basically you should use AddHandler in whatever parent UIElement that has the event.
For me, I did this in my MainWindow. So my code looked like:
This will also mean not overriding OnMouseWheelDown, but instead creating a method that matches the RoutedEventHandler delegate and casting e (which will be a RoutedEventArg) as MouseWheelEventArgs to get access to the properties required to determining zoom.
I hope this helps for your situation.