I have created a silverlight 4 application and using visifire charting components.
I am using MVVM pattern and have created a view which 开发者_开发技巧contains:
<Charts:Chart x:Name="myChart">
The issue is that the number of data series of the chart will change.
I have got all of the logic in place now and is working if I don't use MVVM model and directly set the myChart's series property.
Now, I want to set the data series collection of the chart in my view model.
I have created a DataSeriesCollection property in view model.
If I was setting data series collection in my backend code (if I was not using MVVM), I would do simply:
this.myChart.Series = MyDataSeriesCollection;
where MyDataSeriesCollection is a collection of DataSeries
but I don't know how I need to set the binding of DataSeriesCollection in the xaml.
As at Sep 2010 it looks like the DataSeries property is not bindable:
See this forum post, aswered by Visifire: Databinding Series property?
It may that Visifire is a few steps behind the latest trends towards MVVM and binding everything.
I've just encountered the same problem as @InfoLearner and I believe that I know how I might address this issue so that I'll be able to dynamically add more DataSeries
objects to my visifire chart using binding.
My idea is to create a UserControl
that holds the Visifire chart within it (only the chart), then, I'll add some dependency properties with the stuff I want to be able to bind to (like DataSeriesCollection
property, Styles etc.) and then I'll hook it up to my chart in the control's code behind. I believe it's the only viable solution until Visifire would be kind enough to provide their controls with properly bindable properties.
HTH.
精彩评论