1

I decided to use Modern UI (Metro) Charts for WPF in my application. I have asked for help with this on the developers website but there is no activity there.

The package: http://modernuicharts.codeplex.com

I am trying to bind a DataGrid and a PieChart to the same ObservableCollection, however when I view the chart all it shows is a "0", the legend shows correctly (see image)

https://i.stack.imgur.com/HL20V.png

The DataGrid shows correctly, when I remove the ItemSource binding from the DataGrid the graph will show properly. Any idea what is causing this? Below is the relevant code:

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

Chart:

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

Viewmodel:

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

My goal is that I want to be able to edit data in the DataGrid and that these changes will alter the graph.

Any help is appreciated!

user3692104
  • 189
  • 2
  • 13
  • Unfortunately I haven't used those chart controls, but in general in WPF, there is no problem with data binding two or more controls to the same data source. – Sheridan Sep 02 '14 at 10:35

0 Answers0