“Modern UI (Metro) Charts for Windows 8, WPF, Silverlight” for .net 4.0


0 Answers

I had to do two things to get it to work with VS2010. The first was that the databinding wasn't being brought along when setting the DataContext for ChartBase. That resulted in no data to plot. To fix that I changed ChartBase.OnSeriesSourceChanged to use LoadDataTemplate that loads the content then loops through and sets all the databindings:

private void OnSeriesSourceChanged(IEnumerable oldValue, IEnumerable newValue)
{
    this.Series.Clear();
    if (newValue != null)
    {
        foreach (object item in newValue)
        {
            if (SeriesTemplate != null)
            {
                ChartSeries series = LoadDataTemplate<ChartSeries>(SeriesTemplate, item);
                if (series != null)
                {
                    // set data context
                    series.DataContext = item;
                    this.Series.Add(series);
                }
            }
        }
    }
    UpdateGroupedSeries();
}

private static T LoadDataTemplate<T>(DataTemplate template, object dataContext)
    where T : FrameworkElement
{
    DependencyObject element = template.LoadContent();
    T view = element as T;
    view.DataContext = dataContext;

    var enumerator = element.GetLocalValueEnumerator();
    while (enumerator.MoveNext())
    {
        var bind = enumerator.Current;

        if (bind.Value is BindingExpression)
        {
            view.SetBinding(bind.Property, ((BindingExpression)bind.Value).ParentBinding);
        }
    }

    return view;
}

Second I had to change the project to including the correct Generic.xaml file. Be sure to use the one under De.TorstenMandelkow.MetroChart.WPF/Themes. It needs to include the BaseChartStyle.

HTH

Question

I'm searching for a good chart-control and found "Modern UI (Metro) Charts for Windows 8, WPF, Silverlight" This control looks really good but I need this for Visual Studio 2010 and 4.0. The original source is written in Visual Studio 2012 und 4.5 so I tried to create a new project with the class files. Everything works well. I can compile the classes and debug thru. But the result is an empty window. I don't know where the mistake is. The files are unchanged thats why I post some pictures:

the working sample

copied 4.0 sample

the working sample Snoop

copied 4.0 sample Snoop




Related



Tags