Ask a questionAsk a question
 

AnswerMouseBinding wheel rotation - both directions?

  • Tuesday, February 06, 2007 4:09 PMMartin2233 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I see I can use MouseAction.WheelClick to react to wheel rotation. Is there a way to create different MouseBinding for rotation in one and another direction, or the only way to react differently to rotation in different directions is to to forget MouseBinding and create appropriate mouse events handlers?

    Thanks,

    Martin

Answers

  • Tuesday, February 06, 2007 5:34 PMBrownie PointsMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Try using the Mouse.MouseWheel event. The handler receives a MouseWheelEventArgs parameter that has a Delta property that is positive when the user scrolls the mousewheel up and negative when he (or she) scrolls it down.

    The event is attached but is also defined directly on all WPF controls that implement IInputElement (seeing that Control implements IInputElement that is every control).

  • Tuesday, February 06, 2007 6:27 PMBrownie PointsMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    I see what you're saying now. It doesn't appear that there is a separate MouseAction for wheel scroll up vs. down. Honestly, I'm not even sure if WheelClick does anything different than registering if the wheel is clicked or rotated. Maybe the WPF team can get that in for 3.5?
  • Wednesday, September 19, 2007 2:30 PMCaleb Vear Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Actually you don't have to use the MouseWheelEvent.  It is quite easy to create a new type of MouseGesture that allows you to set a gesture for moving the mouse wheel up or down.  I have detailed how I did this on my blog.  You can find my article called Creating a Customer InputGesture for Mouse Wheel Movements.

     

    Cheers,

     

    Caleb

     

All Replies

  • Tuesday, February 06, 2007 5:34 PMBrownie PointsMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Try using the Mouse.MouseWheel event. The handler receives a MouseWheelEventArgs parameter that has a Delta property that is positive when the user scrolls the mousewheel up and negative when he (or she) scrolls it down.

    The event is attached but is also defined directly on all WPF controls that implement IInputElement (seeing that Control implements IInputElement that is every control).

  • Tuesday, February 06, 2007 5:55 PMMartin2233 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Mike, thanks for taking your time to response to my question.

    As I indicated in the question, I know I can use MouseWheel event handler in code behind to react differently to mouse wheel rotation directions. What I wanted to know is whether it is possible to create different MouseBindings  for different directions of rotation (or e.g. MouseBinding for only one direction), that is in XAML something like:

    <Window.InputBindings>
        <!-- this element is valid XAML element which unfortunately reacts to movement in any direction of mouse wheel -->
        <MouseBinding MouseAction="WheelClick" Command="Cmd1" />

        <!-- next two elements are invalid according to XAML schema, they are made up by me to illustrate there is something more needed to allow XAML authors to bind commands not only to key bindings and mouse clicks, but also to different directions of mouse wheel rotation -->
        <MouseBinding MouseAction="WheelClick" Gesture="DirectionUp" Command="Cmd2" />
        <MouseBinding MouseAction="WheelClick" Gesture="DirectionDown" Command="Cmd3" />
    </Window.InputBindings>


    WARNING: This just an illustrative, uncompilable, made up example.


    Hopefully the question is more clear now.

    Martin
  • Tuesday, February 06, 2007 6:27 PMBrownie PointsMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    I see what you're saying now. It doesn't appear that there is a separate MouseAction for wheel scroll up vs. down. Honestly, I'm not even sure if WheelClick does anything different than registering if the wheel is clicked or rotated. Maybe the WPF team can get that in for 3.5?
  • Wednesday, February 07, 2007 3:05 PMMartin2233 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    It's got my vote. It'd nice.

    Martin
  • Wednesday, September 19, 2007 2:30 PMCaleb Vear Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Actually you don't have to use the MouseWheelEvent.  It is quite easy to create a new type of MouseGesture that allows you to set a gesture for moving the mouse wheel up or down.  I have detailed how I did this on my blog.  You can find my article called Creating a Customer InputGesture for Mouse Wheel Movements.

     

    Cheers,

     

    Caleb

     

  • Wednesday, September 19, 2007 2:53 PMMartin2233 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    This is the solution I've been looking for. Good work and thanks for sharing it!

  • Thursday, November 19, 2009 12:55 PMCiantic Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I created a suggestion to MSDN Connect:


    Go vote if you care about this!