using SciChart.Charting.Model.ChartSeries; using SciChart.Charting.Model.DataSeries; using SciChart.Charting.Visuals.Annotations; using SciChart.Charting.Visuals.Events; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace Regress.WPF.Extensions { public class VerticalLineExtension: VerticalLineAnnotationViewModel { private int startpointidx; private IComparable startpointvalue; public IDataSeries ParentSeries { get; set; } public VerticalLineExtension():base() { this.DragDelta += VerticalLineExtension_DragDelta; this.DragStarted += VerticalLineExtension_DragStarted; } private void VerticalLineExtension_DragStarted(object sender, EventArgs e) { startpointidx = ((XyDataSeries)ParentSeries).FindIndex(X1, SciChart.Charting.Common.Extensions.SearchMode.Nearest); if (startpointidx>=0) startpointvalue = ((XyDataSeries)ParentSeries).XValues[startpointidx]; } public event EventHandler DragToPoint; private void VerticalLineExtension_DragDelta(object sender, SciChart.Charting.Visuals.Events.AnnotationDragDeltaEventArgs e) { var newNearestValueIndex =((XyDataSeries) ParentSeries).FindIndex(X1,SciChart.Charting.Common.Extensions.SearchMode.Nearest ); if (newNearestValueIndex < 0 || startpointidx < 0) return; var NearestValue = ((XyDataSeries)ParentSeries).XValues[newNearestValueIndex]; if (startpointidx == newNearestValueIndex) X1 = startpointvalue; else { X1 = NearestValue; if (DragToPoint != null) DragToPoint.Invoke(sender, new AnnotationDragToPointEventArgs { OldIndex = startpointidx, NewIndex = newNearestValueIndex }); startpointidx = newNearestValueIndex; startpointvalue = NearestValue; } } public int Valuetype { get; set; } } public class AnnotationDragToPointEventArgs:EventArgs { public int OldIndex { get; set; } public int NewIndex { get; set; } } }