PanAndZoomBehavior Mouse Buttons

4 posts, 0 answers
  1. Markus
    Markus avatar
    42 posts
    Member since:
    Nov 2012

    Posted 29 Oct 2013 Link to this post

    Hi,
    is it possible to put the zoom behavior on the right mouse button and the pan behavior on the center mouse button?

    Regards Markus
  2. Markus
    Markus avatar
    42 posts
    Member since:
    Nov 2012

    Posted 30 Oct 2013 Link to this post

    Hi,
    now I have this:

    private const UInt32 MouseEventLeftDown = 0x0002;
    private const UInt32 MouseEventLeftUp = 0x0004;
    [DllImport("user32", EntryPoint = "mouse_event")]
    private static extern void mouse_event(UInt32 dwFlags, UInt32 dx, UInt32 dy, UInt32 dwData, UInt32 dwExtraInfo);
     
    private void chartView_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
    {
     if (e.ChangedButton == System.Windows.Input.MouseButton.Middle)
     {
      PanAndZoom.DragMode = ChartDragMode.Pan;
      mouse_event(MouseEventLeftDown, 0, 0, 0, 0);
     }
    }
     
    private void chartView_MouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
    {
     if (e.ChangedButton == System.Windows.Input.MouseButton.Middle)
     {
      mouse_event(MouseEventLeftUp, 0, 0, 0, 0);      
      PanAndZoom.DragMode = ChartDragMode.Zoom;   
     }
    }

    When I press the middle mouse button the chart is successfully panning. But when I release it there is also a zoom. Why?

    Regards Markus
  3. UI for WPF is Visual Studio 2017 Ready
  4. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 30 Oct 2013 Link to this post

    Hello Markus,

    The most likely reason for this is that the mouse wheel is rotated and the MouseWheel event is raised, which in turn zooms the chart in and out. You can change this by setting the MouseWheelMode property of the ChartPanAndZoomBehavior.

    Regards,
    Petar Marchev
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  5. Markus
    Markus avatar
    42 posts
    Member since:
    Nov 2012

    Posted 30 Oct 2013 Link to this post

    Hi,
    I noticed that when I release the button, the zoom mode is activated for a bit. So I'm zooming in. Workaround for this is:

    [DllImport("user32.dll")]
    public static extern bool ReleaseCapture();
     
    private void chartView_MouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
    {
     if (e.ChangedButton == System.Windows.Input.MouseButton.Middle)
     {
      mouse_event(MouseEventLeftUp, 0, 0, 0, 0);      
      PanAndZoom.DragMode = ChartDragMode.Zoom;
      ReleaseCapture();
     }
    }

    With the ReleaseCapture set, there is no zooming.

    Regards Markus
Back to Top