0

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."

1 Answers1

0

At this point, Generic type only has very limited support in xaml.

XamlWriter cannot serialize a property of a generic list type. You can try the following workaround to fix the issue.

public class OxyPlot
{
    public OxyColors OxyColor { get; set; }
}

public class OxyColors : List<OxyColor>
{

}

public class OxyColor
{

}
Cinchoo
  • 6,088
  • 2
  • 19
  • 34