1

我决定在我的应用程序中为 WPF 使用 Modern UI (Metro) Charts。我已经在开发者网站上寻求帮助,但那里没有任何活动。

包: http: //modernuicharts.codeplex.com

我正在尝试将 DataGrid 和 PieChart 绑定到同一个 ObservableCollection,但是当我查看图表时,它显示的只是“0”,图例显示正确(见图)

http://i.imgur.com/V2YJbCJ.png

DataGrid 显示正确,当我从 DataGrid 中删除 ItemSource 绑定时,图形将正确显示。知道是什么原因造成的吗?下面是相关代码:

<DataGrid ItemsSource="{Binding Path=Errors}" AutoGenerateColumns="True">

图表:

<Chart:PieChart.Series>
     <Chart:ChartSeries 
               SeriesTitle="Populations"
               DisplayMember="Category"
               ValueMember="Number"
               ItemsSource="{Binding Path=Errors}"/>
</Chart:PieChart.Series>

视图模型:

public class MainViewModel
{

    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 });
    }

    public ObservableCollection<TestClass> Errors
    {
        get;
        set;
    }
}

public class TestClass : INotifyPropertyChanged
{
    private string _category = "";
    public string Category
    {
        get
        {
            return _category;
        }
        set
        {
            _category = value;
            if (PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs("Category"));
            }
        }
    }

    private double _number = 0;
    public double Number
    {
        get
        {
            return _number;
        }
        set
        {
            _number = value;
            if (PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs("Number"));
            }
        }

    }

    public event PropertyChangedEventHandler PropertyChanged;
}

我的目标是我希望能够编辑 DataGrid 中的数据,并且这些更改将改变图形。

任何帮助表示赞赏!

4

0 回答 0