I generated a PageBuilder different UI-Models (TextBlocks, Images) for creating a XAMLLayout. For this I placed all my Elements on a Canvas and save the complete Canvas to a Xaml-File (With the XamlWriter.Save-Method).
Now I need to generate Charts and serialize them. With the OxyPlot-Library i used this code for generating the code via runtime.
OxyPlot.Wpf.PlotView pv = new OxyPlot.Wpf.PlotView();
OxyPlot.PlotModel pm = new OxyPlot.PlotModel();
pv.Height = 300;
pv.Width = 500;
pv.Background = Brushes.Red;
pm.Title = "Test";
pm.Series.Add(new OxyPlot.Series.FunctionSeries(Math.Cos, 0, 10, 0.1, "cos(x)"));
pv.Model = pm;
canvas.Children.Add(pv);
For the serialisation I just call my Canvas and serialize the whole objects like this this:
XamlWriter.Save(canvas);
Durring this process I got an exception:
System.InvalidOperationException: "The generic type" System.Collections.Generic.List`1 [OxyPlot.OxyColor] "can not be serialized."