简体   繁体   中英

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

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 复制4.0样本

the working sample Snoop 工作样本Snoop

copied 4.0 sample Snoop 复制4.0样本Snoop

The new Metro Charts are really good! Like you've mentioned, they are targetting Windows 8 and .net 4.5, but you can get them to run on Windows 7 with .net 4.0 in VS 2010 as well. Take a look at http://thusithamabotuwana.wordpress.com/2014/02/02/charting-with-wpf/ if you need a quick tutorial on how to get started.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM