如何支持使用触控板/水平滚轮横向滚动?

How to support sideways scrolling with trackpad / horizontal scroll wheel?

我有一个支持缩放的 SciChartSurface,如下所示:

当用户在触控板上水平滚动或使用水平滚轮(拇指轮)时,我还想启用 X 方向的平移。但是,我不确定该怎么做。

这是我一直在使用的扩展 MouseWheelZoomModifier。我能以某种方式向它发送有关我的滚动行为的信息吗?我能以某种方式将 sideways/horizontal 滚动视为 Shift + 滚动吗?谢谢!

/// <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);
    }
}

在 SciChart 中,您可以使用 ChartModifierBase API 添加任何自定义缩放和平移行为。

除了可以覆盖的标准方法(如 OnModifierMouseWheel、OnModifierMouseDown、OnModifierMouseUp)之外,您还可以直接在 ParentSurface 上订阅事件。

看看这篇知识库文章:Custom ChartModifiers - Part 2 - Custom ZoomPanModifier and Zooming on KeyPress

最新 accompanying source code is here

所以我的建议是采用 SimpleZoomInOutModifier 并对其进行修改以响应鼠标滚轮事件而不是按键事件。

有帮助吗?