I am using the xamDataChart in an application where I serialize the viewmodel so I can persist the settings to the graph control. This is necessary because the series created are unknown at compile time and the data is unknown until runtime. I add series to the chart by binding to the graph SeriesCollection and adding series to this collection per user interaction.
All of my graph operation works fine, however since this SeriesCollection is read only, when I try to deserialize my viewmodel, I can't as I have no reference in my viewmodel to the graph control. Why is the graph SeriesCollection read only? This leads me to believe that this graph is not truly MVVM compliant...
Hi Ed,
The SeriesCollection is read only because we do not want the collection instance to change. Why does deserializing the view model need a settable SeriesCollection? When you deserialize can you not clear the existing SeriesCollection and add the deserialized Series objects back into it? I'm also not sure how you binded to this collection since it has no setter and it is not a DependencyProperty.
About the only way I've seen to dynamically create series at runtime from the view model has been to do something like this: http://stackoverflow.com/questions/18857830/xamdatachart-with-unknown-number-of-series
A 770 line code behind file to do MVVM databinding? That is completely unacceptable!
It is 770 lines because all the classes required to do the binding have been placed into the code-behind file for simplicity. These classes can be moved to separate files which would leave the code behind file empty except for the MainWindow constructor which is always there. These classes are necessary because you cannot directly bind to the Series collection. In order to take a collection of series view model objects from the view model and generate the appropriate series in the UI from them those classes handle the translation.
I believe this is the correct way to do it because the objects that are added to the Series collection are UI elements and the view model should not be touching or creating UI elements. LineSeries, ColumnSeries, BarSeries, etc. are all UI elements that will be physically placed into the Visual Tree. So in order to bind some collection in the view model to the UI and have it generate series, something like the code in that sample is necessary.