0

我有一个PlotModelLineSeries画的。我正在寻找的是选择由MouseDown事件检测到的点所属的所有 LineSeries 的技巧。

我已经这样做了:

this.MouseDown += CheckIfLineSeriesHasBeenSelected;

private void CheckIfLineSeriesHasBeenSelected(object sender, OxyMouseDownEventArgs e)
{
     switch (e.ChangedButton)
     {
          case OxyMouseButton.Left:
               var series = (LineSeries) this.GetSeriesFromPoint(e.Position, 10);
               series.StrokeThickness = 4;
           break;
      }
 }

但是通过这种方式,模型只改变了整个 LineSeries 的一小部分的厚度。你有什么建议吗?谢谢!

4

1 回答 1

0

您可以随机搜索e.Position并选择系列:

    private void PlotModel_MouseDown(object sender, OxyMouseDownEventArgs e)
    {
        int radius = 5;
        List<LineSeries> ss = new List<LineSeries>();
        searchAndAdd(ref ss, e.Position);
        Random rand = new Random();
        for (int i = 0; i < 100; i++)
        {
            double x = rand.Next(-radius, radius);
            double y = rand.Next(-radius, radius);
            ScreenPoint pos = new ScreenPoint(e.Position.X + x, e.Position.X);
            searchAndAdd(ref ss, pos);
        }
        foreach (var s in ss)
            s.StrokeThickness = 8;
        plotModel.InvalidatePlot(false);
    }
    void searchAndAdd(ref List<LineSeries> series, ScreenPoint pos)
    {
        var s = plotModel.GetSeriesFromPoint(pos, 10) as LineSeries;
        if (s != null && series.Contains(s) == false)
            series.Add(s);
    }

请注意,这radius决定了您要搜索的距离。另请注意,您应该plotModel.InvalidatePlot(false);在最后打电话。

于 2017-03-05T10:32:28.417 回答