Question

I am trying to use databinding to bind data to a Silverlight toolkit chart. I will have one to many sets of series so cannot determine how many series i need before hand. I also want to stick to a databinding model and not resort to programmatically adding these series as many other controls bind to this datasource.

I found an article on the web by Jeremiah Morrill that showed a solution for this very problem.

Jeremiah's solution

Now this worked perfectly at first, until I tried to update my databinding's datasource values while the application was running, and this would not reflect. As if it was not subscribed to the PropertyChanged event. I even bound the same data to a datagrid next to the chart, and the datagrid reacts as expected changing everytime my databinding's datasource values change.

In my ChartHelper from Jeremiah's solution, i have the following dependency property

public static readonly DependencyProperty SeriesSourceProperty =
        DependencyProperty.RegisterAttached("SeriesSource", 
                                            typeof(IEnumerable), 
                                            typeof(ChartHelper),
                                            new PropertyMetadata(SeriesSourceChanged));

The SeriesSourceChanged event is called when my application starts up. However, when my DataBinding's datasource values change, this is not called again.

So questions are as follows:

  • How can I capture the PropertyChanged notification with this solution?
  • Is there something I can add to the DependencyProperty above to capture this?
  • Is it something i need to add to the chart or series to achieve this?

I have been racking my brain over this for several days, so any help or suggestions will be much appreciated

Thanks!

Was it helpful?

Solution 2

I never did find a solution to this problem and ended up using a chart control from visifire

I found this much easier to customise but never found a neat way of using databinding to achieve this and ended up with a more programattic approach.

OTHER TIPS

The SeriesSource type should be ObservableCollection instead of IEnumerable. Then you do something like this:

private static void SeriesSourceChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
    var sender = o as YourType;
    var newCollection = e.NewValue as ObservableCollection<DataSetViewModel>;
    if (newCollection != null)
    {
        newCollection.CollectionChanged += new NotifyCollectionChangedEventHandler(sender.OnCollectionChanged);
    }
}

private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top