This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I want to create a StackBarChart in Expression Blend by dragging control to the design surface and setting the properties in Properties panel. Assuming I have a view model ready for data binding, how can I bind the data to the chart? Or rather, what properties of the chart should I bind to? The sample shipped with the package set the ItemsSource in the code behind. I tried to used sample data generated by Blend and bind them to the chart in Properties panel, but looks like it doesn't work. |
|
|
Note: I used a custom model class in the collection: class Model { public string Date { get; set; } public int Count { get; set } }
I noticed the sample uses Point class. Is it a must to use the Point class? |
|
|
It is possible to bind the ItemsSource property of a data series to a view model. Usually, you set the DataContext of the application page to be the view model. Then you can set ItemsSource="{Binding MyDataProperty}". All the charts can accept any type of data, not just the Point class. Each data series has an XBinding and YBinding property. You can set these to be a binding to the appropriate properties on your custom data object. So using your Model object, you would do something like this: <ms:StackedBarSeries XBinding="{Binding Date}" YBinding="{Binding Count}" /> Do this to all the series in the chart that are going to use this data object. Let me know if there are still issues. - Jason |
|
|
Hi Jason, It works. Thanks. And if my model implements INotifyPropertyChanged interface, will the chart refresh itself when the value of the properties of my model changes? And one more thing, I noticed in the sample shipped with the package, it used a Point class as series item, and didn't set any XBinding or YBinding. So I'm just curious whether Point is treated specially? - Allen |
|
|
Hello Allen Yes, by making your custom data object implement the INotifyPropertyChanged interface, the chart will be redrawn when one of the property values change. Indeed the Point object is treated specially. This is just for convenience. Regards |
|