0

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.
Binakot
  • 298
  • 5
  • 15
  • The second error is not a huge surprise given it was never serialised in the first place. – Charles Mager May 16 '16 at 08:53
  • Agree. XamlReader cannot serialize LiveChart because of generic type of LiveCharts.Axis list. – Binakot May 16 '16 at 09:24
  • @Binakot Alot of generics in live charts, soon I will add a method to render images directly and make this easier, something like myChart.AsPng() – bto.rdz May 16 '16 at 17:47
  • I don't need a static image of my chart. I need an animated chart inside my FlowDocument. I guess it's required the implementation of custom serialization for generic types. – Binakot May 17 '16 at 05:38

0 Answers0