问题
I am using an Infragistics XamDataChart and want to bind a collection in my view model to the chart's Series property, since I don't know in advance how many line charts I will need to display.
From what I can gather from old posts in the Infragistics support forums, the Series property is read only and thus doesn't support binding directly. A solution is offered here but it seems like overkill for such a simple goal (maybe to me it just seems simple).
Has anyone here done any work with the Infragistics xamDataChart and MVVM? The ultimate goal is to be able to have a collection in my view model that contains a variable number of 'series' that I can just bind to the chart. Now I can probably do this if I just write some code behind for my xaml, access the DataContext (viewModel) and listen to the collection property, directly adding/removing series to the chart as necessary, but I was looking for a more MVVM way.
Thanks.
回答1:
Since the Series collection of the XamDataChart is read-only, in order to be able to generate the Series dynamically,based on you VeiwModel, you should use helper class, similar to the approach that Graham Murray has suggested in the thead that you have referred. I have created a sample applicaiton, that show how you can create similar appraoch for binding the series of the XamDataChart to collection of your ViewModel. You can download the sample from here:
http://users.infragistics.com/Samples/SeriesBinder.zip
Sincerely,
Krasimir
来源:https://stackoverflow.com/questions/18857830/xamdatachart-with-unknown-number-of-series