Pre loader

How can I zoom the chart using mouse wheel, not at mouse pointer center, but at specified point center?

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

Answered
0
0

I want to zoom the chart using mouse wheel. But not zoom at mouse point center, but at the specified point center I set.

How can I do it?
Is there any properties for MouseWheelZoomModifier?

Version
v5.1.1.11473
  • You must to post comments
Best Answer
1
1

Hi there

You can override MouseWheelZoomModifier.OnModifierMouseWheel() to customize the behaviour

For example

    /// <summary>
    /// Called when the Mouse Wheel is scrolled on the parent <see cref="SciChartSurface"/>
    /// </summary>
    /// <param name="e">Arguments detailing the mouse wheel operation</param>
    /// <remarks></remarks>
    public override void OnModifierMouseWheel(ModifierMouseArgs e)
    {
        base.OnModifierMouseWheel(e);

        e.Handled = true;

        const double mouseWheelDeltaCoef = 120;

        using (ParentSurface.SuspendUpdates())
        {
            double value = -e.Delta / mouseWheelDeltaCoef;

            var currDirection = XyDirection;
            var currAction = ActionType;

            OverrideKeyboardAction(e.Modifier);

           // THIS is where we get the mouse point
            var mousePoint = GetPointRelativeTo(e.MousePoint, ModifierSurface);
            _performAction(mousePoint, value);

            TryStoreRangesToZoomHistoryManager();

            this.SetCurrentValue(XyDirectionProperty, currDirection);
            this.SetCurrentValue(ActionTypeProperty, currAction);
    }

Or … the much simpler way – to pass a different point to the base

    public class MouseWheelModifierEx : MouseWheelZoomModifier
    {
        public override void OnModifierMouseWheel(ModifierMouseArgs e)
        {
            // Override the mouse point
            e.MousePoint = new Point(10, 20);

            // Call base
            base.OnModifierMouseWheel(e);
        }
    }

Best regards,
Andrew

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.