thank your for the support and the insight you gave for the problem. Your solution does work and solves the problem. Thanks!
Another more hacky solution would be to extend the SfChart and use another property to bind to an interface of IChartSeries for example.
namespace
{
public class SfChartExtended : SfChart
{
private Dictionary _SeriesMapping = new Dictionary();
public IList ChartItemsSource
{
get { return (IList)GetValue(ChartItemsSourceProperty); }
set { SetValue(ChartItemsSourceProperty, value); }
}
// Using a DependencyProperty as the backing store for ItemsSource. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ChartItemsSourceProperty =
DependencyProperty.Register("ChartItemsSource", typeof(IList), typeof(SfChartExtended), new PropertyMetadata(null));
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
{
if (e.Property.Name == "ChartItemsSource")
{
this.Series = new ChartSeriesCollection();
_SeriesMapping.Clear();
if (e.OldValue != null)
{
var oldcollection = e.OldValue as INotifyCollectionChanged;
oldcollection.CollectionChanged -= OnSeriesChanged;
}
if (e.NewValue != null)
{
var newcollection = e.NewValue as INotifyCollectionChanged;
newcollection.CollectionChanged += OnSeriesChanged;
foreach (var item in ((IList)e.NewValue))
{
addSeries(item as IChartSeries);
}
}
}
base.OnPropertyChanged(e);
}
private void addSeries(IChartSeries series)
{
// Edit this to Bind data and all charts
LineSeries newChartItem = new LineSeries() { XBindingPath = "XData", YBindingPath = "YData", ItemsSource = series.InsertSourceHere };
_SeriesMapping.Add(series,newChartItem);
this.Series.Add(newChartItem);
}
private void removeSeries(IChartSeries series)
{
ChartSeries chartItem = _SeriesMapping.Where(x => x.Key == series).Select(x => x.Value).FirstOrDefault();
_SeriesMapping.Remove(series);
this.Series.Remove(chartItem);
}
private void OnSeriesChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Add && e.NewItems != null)
{
foreach (var item in e.NewItems)
{
addSeries((IChartSeries)item);
}
}
if (e.Action == NotifyCollectionChangedAction.Remove && e.OldItems != null)
{
foreach (var item in e.OldItems)
{
removeSeries((IChartSeries)item);
}
}
}
}
}