5

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

工作样本 工作样本

复制 4.0 示例 复制 4.0 示例

工作样本 Snoop 工作样本 Snoop

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

4

2 回答 2

2

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

于 2014-02-03T19:32:57.927 回答
0

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

于 2013-03-28T15:52:19.357 回答