Hi i am using oxyplot in my wpf application. When I try to add a lineseries object to plotmodel - I get an error
System.InvalidOperationException: "The element cannot be added, it already belongs to a PlotModel."
Here is my code
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);
}
I don't understand how such an error can occur if the PlotModel.Series.Count property = 0 in the newly created PlotModel. Any help would be greatly appreciated.