private void ImagePlot_OnMouseDown(object sender, MouseButtonEventArgs e) { if (Points == null || Points.Count == 0 || PointCenters == null || PointCenters.Length == 0) { return; } System.Windows.Point MousePoint = e.GetPosition(ImagePlot); int ClosestID = GetClosestPoint(MousePoint); List <int> Neighbors = Helper.ArrayOfSequence(Math.Max(0, ClosestID - 5), Math.Min(PointCenters.Length, ClosestID + 5), 1).ToList(); Neighbors.Sort((a, b) => (PointCenters[a] - MousePoint).Length.CompareTo((PointCenters[b] - MousePoint).Length)); ClosestID = Neighbors.First(); System.Windows.Point Closest = PointCenters[ClosestID]; double Dist = (Closest - MousePoint).Length; if (Dist > PointRadius * Zoom * 2) { return; } Dispatcher.InvokeAsync(() => { if (ImagePlot.ToolTip != null) { ((ToolTip)ImagePlot.ToolTip).IsOpen = false; } }); PointClicked?.Invoke(Points[ClosestID].Context); }
private void ImagePlot_OnMouseDown(object sender, MouseButtonEventArgs e) { if (Points == null || Points.Count == 0 || PointCenters == null || PointCenters.Length == 0) { return; } System.Windows.Point MousePoint = e.GetPosition(ImagePlot); int ClosestID = GetClosestPoint(MousePoint); System.Windows.Point Closest = PointCenters[ClosestID]; double Dist = (Closest - MousePoint).Length; if (Dist > PointRadius * 2) { return; } Dispatcher.InvokeAsync(() => { if (ImagePlot.ToolTip != null) { ((ToolTip)ImagePlot.ToolTip).IsOpen = false; } }); PointClicked?.Invoke(Points[ClosestID].Context); }