SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components

Answered
0
0

I’m wondering how to add a DragListener to the YAxis in WPF so that I can tell when my YAxisDragModifier has been invoked. I tried adding a custom EventHandler to the SciChartSurface.YAxis like so: DragEnter=”YAxisDragModifier_DragEnter” but the method wasn’t forwarded any events. I also set ReceiveHandledEvents=”True” in my YAxisDragModifier, but that didn’t seem to help.

Version
v5
  • You must to post comments
Best Answer
1
0

Hi Jacob

If you want to be notified when a YAxisDragModifier is used, please try something like this code:

public class YAxisDragModifierEx : YAxisDragModifier
{
    public event EventHandler<EventArgs> Dragged;

    protected override void PerformPan(Point currentPoint, Point lastPoint)
    {
        base.PerformPan(currentPoint, lastPoint);
        Dragged?.Invoke(this, EventArgs.Empty);
    }

    protected override void PerformScale(Point currentPoint, Point lastPoint, bool isSecondHalf)
    {
        base.PerformScale(currentPoint, lastPoint, isSecondHalf);
        Dragged?.Invoke(this, EventArgs.Empty);
    }
}

Note that this will fire events continuously as the YAxisDragModifier is dragged or panned.

If you want a single event at the end of an operation, try this instead.

public class YAxisDragModifierEx : YAxisDragModifier
{
    private bool wasDragged;
    public event EventHandler<EventArgs> DragEnd;

    protected override void PerformPan(Point currentPoint, Point lastPoint)
    {
        base.PerformPan(currentPoint, lastPoint);
        this.wasDragged = true;
    }

    protected override void PerformScale(Point currentPoint, Point lastPoint, bool isSecondHalf)
    {
        base.PerformScale(currentPoint, lastPoint, isSecondHalf);
        this.wasDragged = true;
    }

    public override void OnModifierMouseUp(ModifierMouseArgs e)
    {
        base.OnModifierMouseUp(e);
        if (this.wasDragged)
        {
            DragEnd?.Invoke(this, EventArgs.Empty);
            this.wasDragged = false;
        }
    }
}

Let me know if that helps! For more info about our powerful chartmodifier API take a look at the ChartModifier Sandbox project on github

Best regards,
Andrew

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.