Here's my code:
public partial class MainWindow : Window
{
public MainWindow()
{
//myOnlyGrid = new Grid();
Chart MyChart = new Chart();
ColumnSeries b = new ColumnSeries();
b.Title = "B";
b.IndependentValueBinding = new System.Windows.Data.Binding("Key");
b.DependentValueBinding = new System.Windows.Data.Binding("Value");
b.ItemsSource = new List<KeyValuePair<string, int>> {
new KeyValuePair<string, int>("1", 100),
new KeyValuePair<string, int>("2", 75),
new KeyValuePair<string, int>("3", 150)
};
MyChart.Series.Add(b);
Grid.SetColumn(MyChart, 0);
Thread.Sleep(1000);
myOnlyGrid.Children.Add(MyChart);
InitializeComponent();
}
and my XAML:
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid Name="myOnlyGrid">
</Grid>
For some reason, it compiles fine but throws a nullreferenceexception whenever it reaches myOnlyGrid.Children.Add(). I've been googling for about an hour and haven't found anything.