I have a problem with LiveCharts and XamlReader (serialization).
MyUserControlWithLiveChart (XAML):
<UserControl>
<Grid>
<liveCharts:LineChart LineSmoothness="0">
<liveCharts:LineChart.Series>
<liveCharts:LineSeries Values="1, 5, 8" />
<liveCharts:LineSeries Values="3, 6, 2" />
</liveCharts:LineChart.Series>
</liveCharts:LineChart>
</Grid>
</UserControl>
FlowDocument (XAML):
<FlowDocument>
<BlockUIContainer x:Name="ReportContainer">
<!-- I add my UserControl with LiveChart here in runtime. -->
</BlockUIContainer>
</FlowDocument>
Create MyUserControlWithLiveChart and add it as child into BlockUIContainer (C#):
_mainWindow.Dispatcher.Invoke(new Action(delegate()
{
var chartControl = new MyUserControlWithLiveChart();
ReportContainer.Child = chartControl;
}));
When my FlowDocument is ready, I serialize it into StreamMemory in background thread (C#):
_stream = new MemoryStream();
_mainWindow.Dispatcher.BeginInvoke(new Action(delegate ()
{
XamlWriter.Save(_myFlowDocument, _stream); // #1 ERROR HERE!
_stream.Position = 0;
}));
After I de-serialize my FlowDocument in main UIThread and try to show it in FlowDocumentScrollViewer (C#):
_mainWindow.Dispatcher.BeginInvoke(new Action(delegate ()
{
_myFlowDocument = (FlowDocument)XamlReader.Load(_stream); // #2 ERROR HERE!
_stream.Close();
_mainWindow.MyFlowDocumentScrollViewer.Document = _myFlowDocument;
}));
But when i try to de-serealize my FlowDocument with LiveChart control, i got exception.
1 Error:
Cannot serialize a generic type
"System.Collections.Generic.List`1[LiveCharts.Axis]"
2 Error:
XamlParserEception occurred.
Exception thrown: 'System.Windows.Markup.XamlParseException' in PresentationFramework.dll
Additional information: Root element is missing.