简体   繁体   English

“适用于Windows 8的现代UI(Metro)图表,WPF,Silverlight”,适用于.net 4.0

[英]“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. 我正在寻找一个好的图表控件,并找到了“ 适用于Windows 8,WPF,Silverlight的现代UI(Metro)图表 ”这个控件看起来非常好,但我需要这个用于Visual Studio 2010和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. 原始源代码是用Visual Studio 2012和4.5编写的,所以我尝试用类文件创建一个新项目。 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样本 复制4.0样本

the working sample Snoop 工作样本Snoop 工作样本Snoop

copied 4.0 sample Snoop 复制4.0样本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. 就像你提到的那样,他们的目标是Windows 8和.net 4.5,但是你也可以在VS 2010中使用.net 4.0在Windows 7上运行它们。 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. 如果您需要有关如何入门的快速教程,请查看http://thusithamabotuwana.wordpress.com/2014/02/02/charting-with-wpf/

I had to do two things to get it to work with VS2010. 我不得不做两件事来让它与VS2010一起工作。 The first was that the databinding wasn't being brought along when setting the DataContext for ChartBase. 第一个是在为ChartBase设置DataContext时没有带来数据绑定。 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: 为了解决这个问题,我更改了ChartBase.OnSeriesSourceChanged以使用加载内容的LoadDataTemplate然后遍历并设置所有数据绑定:

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. 其次,我必须将项目更改为包含正确的Generic.xaml文件。 Be sure to use the one under De.TorstenMandelkow.MetroChart.WPF/Themes. 一定要使用De.TorstenMandelkow.MetroChart.WPF / Themes下的那个。 It needs to include the BaseChartStyle. 它需要包含BaseChartStyle。

HTH HTH

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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