2

I've got a SciChartSurface where I support zooming as follows:

  • Zoom x-axis on regular scrolling.
  • Zoom y-axis on scrolling + CTRL
  • Pan x-axis on scrolling + Shift

I'd like to also enable panning in the X-direction when the user either scrolls horizontally on a trackpad or uses a horizontal scroll wheel (thumb-wheel). However, I'm not sure how to go about doing this.

Here's the extended MouseWheelZoomModifier I've been using. Can I somehow send it information about my scrolling behavior? Can I somehow just treat the sideways/horizontal scrolling as Shift + scroll? Thanks!

/// <summary>
/// Extended <see cref="MouseWheelZoomModifier"/> which modifies zoom
/// behavior based on modifier keys so that scrolling while holding CTRL 
/// zooms vertically and doing so while holding SHIFT pans horizontally.
/// </summary>
class MouseWheelZoomModifierEx : MouseWheelZoomModifier {
    public override void OnModifierMouseWheel(ModifierMouseArgs e) {
        switch (e.Modifier) {
            case MouseModifier.Ctrl:
                ActionType = ActionType.Zoom;
                XyDirection = XyDirection.YDirection;
                break;
            case MouseModifier.Shift:
                ActionType = ActionType.Pan;
                XyDirection = XyDirection.XDirection;
                break;
            default:
                ActionType = ActionType.Zoom;
                XyDirection = XyDirection.XDirection;
                break;
        }

        // e.Modifier is set to None so that the base implementation of 
        // OnModifierMouseWheel doesn't change ActionType and XyDirection again.
        e.Modifier = MouseModifier.None;
        base.OnModifierMouseWheel(e);
    }
}

1 Answers1

1

In SciChart you can add any custom zoom and pan behaviors using the ChartModifierBase API.

As well as the standard methods which you can override (like OnModifierMouseWheel, OnModifierMouseDown, OnModifierMouseUp) you can also subscribe to events directly on the ParentSurface.

Have a look at this KB article: Custom ChartModifiers - Part 2 - Custom ZoomPanModifier and Zooming on KeyPress.

Up to date accompanying source code is here.

So my suggestion is take the SimpleZoomInOutModifier and modify it to respond to mouse wheel events instead of key events.

Does that help?

Dr. Andrew Burnett-Thompson
  • 20,980
  • 8
  • 88
  • 178
  • Thank you for the quick and helpful response! This seems like a good solution, however I've discover that my underlying problem is that the horizontal mouse scroll event isn't being registered anywhere in the application... I'll just have to do some more research. Will update this post if I find an answer. – paul.frivold Jun 30 '17 at 23:13
  • Hi Paul, in the above sample I shared we hook into keydown events which are not subscribed in the application. You can use the same technique for horizontal mouse wheel. Best regards, Andrew – Dr. Andrew Burnett-Thompson Jul 01 '17 at 10:51
  • I'm referring to the SimpleZoomInOutModifier in this KB article. http://support.scichart.com/index.php?/Knowledgebase/Article/View/17236/32/custom-chartmodifiers---part-2---custom-zoompanmodifier-and-zooming-on-keypress Notice how we subscribe to key events on the parent window. You can do the same with Horizontal Mouse Wheel – Dr. Andrew Burnett-Thompson Jul 01 '17 at 11:13
  • Unfortunately, I'm strugglig to at all find the Horizonal Mouse Wheel event on the parent window, not just in scichart. – paul.frivold Jul 02 '17 at 03:30
  • 1
    "How to subscribe to horizontal scroll events in WPF" sounds like the topic of another Stackoverflow question ;) https://www.codeproject.com/Articles/220255/Improving-WPF-Mouse-Wheel-Processing#tuto_hscroll – Dr. Andrew Burnett-Thompson Jul 02 '17 at 07:43