OxyPlot. The element cannot be added, it already belongs to a PlotModel

я использую oxyplot в своем приложении wpf. Когда я пытаюсь добавить объект lineseries в plotmodel - я получаю сообщение об ошибке

System.InvalidOperationException: "The element cannot be added, it already belongs to a PlotModel."

Вот мой код

public PlotController MyPlotController { get; set; }
public PlotModel MyPlotModel { get; set; }
public PlotVM()
{
    MyPlotController = new PlotController();
    MyPlotModel = new PlotModel();
}
public void Plot(List<LineSeries> lineSeriesData)
{
    MyPlotModel.Series.Clear();
    foreach (Series serie in lineSeriesData)
    {
        try
        {
            MyPlotModel.Series.Add(serie); //Get error here
        }
        catch (InvalidOperationException ex)
        {
            MyPlotModel = new PlotModel();
            MyPlotModel.Series.Add(serie); //Get error here
        }
    }
    MyPlotModel.InvalidatePlot(true);
}

Я не понимаю, как такая ошибка может возникнуть, если свойство PlotModel.Series.Count = 0 во вновь созданной PlotModel. Буду благодарен любой помощи.


Ответы (0 шт):