现代 UI(地铁)图表 WPF 未显示

Modern UI (Metro) Charts WPF not showing up

我正在为我的项目使用 .NET Framework 4.5 和 WPF。我需要生成几种类型的图表,所以我想使用 http://modernuicharts.codeplex.com/ library to do that. I followed the documentation there in that codeplex page : http://modernuicharts.codeplex.com/documentation 并完成了这些步骤。

现在我在 Visual Studio13 中没有收到任何类型的错误或警告消息,只是图表没有显示。我只能看到图表的标题和副标题。

导致此问题的可能原因是什么以及如何解决这些问题?

谢谢

XAML代码:

<Canvas Margin="570,90,29,92" Background="White" >
                <chart:PieChart
        Style="{StaticResource MinimalChartStyle}"
        ChartTitle="Minimal Pie Chart"
        ChartSubTitle="Chart with fixed width and height"
        SelectedItem="{Binding Path=SelectedItem, Mode=TwoWay}" >
                    <chart:PieChart.Series>
                        <chart:ChartSeries
                SeriesTitle="Errors"
                DisplayMember="Category"
                ValueMember="Number"
                ItemsSource="{Binding Path=Errors}" />
                    </chart:PieChart.Series>
                </chart:PieChart>
            </Canvas>

用作 dataContext 的 ViewModel Class :

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ModernUIForWPFSample.WithoutBackButton.Views
{
    public class MainViewModel
    {
        public ObservableCollection<TestClass> Errors { get; private set; }

        public MainViewModel()
        {
            Errors = new ObservableCollection<TestClass>();
            Errors.Add(new TestClass() { Category = "Globalization", Number = 75 });
            Errors.Add(new TestClass() { Category = "Features", Number = 2 });
            Errors.Add(new TestClass() { Category = "ContentTypes", Number = 12 });
            Errors.Add(new TestClass() { Category = "Correctness", Number = 83});
            Errors.Add(new TestClass() { Category = "Best Practices", Number = 29 });
        }

        private object selectedItem = null;
        public object SelectedItem
        {
            get
            {
                return selectedItem;
            }
            set
            {
                // selected item has changed
                selectedItem = value;                
            }
        }
    }

    // class which represent a data point in the chart
    public class TestClass
    {
        public string Category { get; set; }

        public int Number  { get; set; }        
    }

}

在代码中 Bihind :

public FinalAnalysis()
        {
            InitializeComponent();
            this.DataContext = new MainViewModel();
        }

这是一个工作示例:

应用XAML:

<Application x:Class="WpfApplication1.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml"
             xmlns:chart="clr-namespace:De.TorstenMandelkow.MetroChart;assembly=De.TorstenMandelkow.MetroChart">
    <Application.Resources>
        <ResourceDictionary>
            <Style x:Key="MinimalChartStyle" TargetType="chart:ChartBase">
                <Setter Property="Width" Value="500"/>
                <Setter Property="Height" Value="500"/>
            </Style>
        </ResourceDictionary>
    </Application.Resources>
</Application>

主窗口XAML:

<Window 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        x:Class="WpfApplication1.MainWindow"
        Title="MainWindow" Height="1500" Width="1525"
        xmlns:metroChart="clr-namespace:De.TorstenMandelkow.MetroChart;assembly=De.TorstenMandelkow.MetroChart">


        <metroChart:PieChart
        Style="{StaticResource MinimalChartStyle}"
        ChartTitle="Minimal Pie Chart"
        ChartSubTitle="Chart with fixed width and height"
        SelectedItem="{Binding Path=SelectedItem, Mode=TwoWay}" >
            <metroChart:PieChart.Series>
                <metroChart:ChartSeries
                SeriesTitle="Errors"
                DisplayMember="Category"
                ValueMember="Number"
                ItemsSource="{Binding Path=Errors}" />
            </metroChart:PieChart.Series>
        </metroChart:PieChart>

</Window>

主窗口坐标:

public MainWindow()
{

    InitializeComponent();
    DataContext = new MainViewModel();
}

MainWindowViewModel 和你的一样,这里就不复制粘贴了。注意装配声明:

 xmlns:metroChart="clr-namespace:De.TorstenMandelkow.MetroChart;assembly=De.TorstenMandelkow.MetroChart"

别忘了在 App 中添加样式 xaml