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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15671754/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 08:21:08  来源:igfitidea点击:

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

c#.netwpfxamlcharts

提问by masterchris_99

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:

我正在寻找一个好的图表控件,并找到了“适用于 Windows 8、WPF、Silverlight 的现代 UI(地铁)图表”这个控件看起来非常好,但我需要它用于 Visual Studio 2010 和 4.0。原始源代码是在 Visual Studio 2012 和 4.5 中编写的,因此我尝试使用类文件创建一个新项目。一切正常。我可以编译类并调试。但结果是一个空窗口。我不知道错误在哪里。文件没有改变,这就是我发布一些图片的原因:

the working samplethe working sample

工作样本工作样本

copied 4.0 samplecopied 4.0 sample

复制 4.0 样本复制 4.0 样本

the working sample Snoopthe working sample Snoop

工作样本 Snoop工作样本 Snoop

copied 4.0 sample Snoopcopied 4.0 sample Snoop

复制 4.0 示例 Snoop复制 4.0 示例 Snoop

回答by Thusi

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.

新的地铁图真的很棒!就像您提到的那样,它们的目标是 Windows 8 和 .net 4.5,但您也可以让它们在 VS 2010 中使用 .net 4.0 的 Windows 7 上运行。如果您需要有关如何入门的快速教程,请查看http://thusithamabotuwana.wordpress.com/2014/02/02/charting-with-wpf/

回答by Scott Mann

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:

我必须做两件事才能让它与 VS2010 一起工作。第一个是在为 ChartBase 设置 DataContext 时没有带来数据绑定。这导致没有要绘制的数据。为了解决这个问题,我将 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. Be sure to use the one under De.TorstenMandelkow.MetroChart.WPF/Themes. It needs to include the BaseChartStyle.

其次,我必须将项目更改为包含正确的 Generic.xaml 文件。请务必使用 De.TorstenMandelkow.MetroChart.WPF/Themes 下的那个。它需要包含 BaseChartStyle。

HTH

HTH