1

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

  • 在常规滚动时缩放 x 轴。
  • 滚动时缩放 y 轴 +CTRL
  • 滚动时平移 x 轴 +Shift

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

这是我一直在使用的扩展 MouseWheelZoomModifier。我可以以某种方式向它发送有关我的滚动行为的信息吗?我可以以某种方式将横向/水平滚动视为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);
    }
}
4

1 回答 1

1

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

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

看看这篇知识库文章:自定义 ChartModifiers - 第 2 部分 - 自定义 ZoomPanModifier 和 KeyPress 上的缩放

最新的随附源代码在这里

所以我的建议是使用 SimpleZoomInOutModifier 并修改它以响应鼠标滚轮事件而不是按键事件。

这有帮助吗?

于 2017-06-29T15:56:04.350 回答