Page 1 of 1

Creating a nerw chart and adding it to a Grid control in WPF

Posted: Mon Mar 31, 2008 8:28 pm
by 9788264
OK, this is probably obvious. I want to dynamically create a chart and add it to a grid in WPF. I thought it would be this simple:

Code: Select all

            //...Create a row in the grid
            RowDefinition chartRowDef = new RowDefinition();
            chartRowDef.Height = new GridLength(200);
            MyGrid.RowDefinitions.Add(chartRowDef);
            //...Create the chart
            Steema.TeeChart.Chart chart = new Steema.TeeChart.Chart();
            //...And add it to the grid control
            MyGrid.Children.Add(chart); //<--- WONT COMPILE!
This will not compile, since chart is type Steema.TeeChart.Chart, and the grid requires a System.Windows.UIElement.

How do I accomplish this?

Thanks,
Mike B.

Re: Creating a nerw chart and adding it to a Grid control in

Posted: Tue Apr 01, 2008 7:18 am
by Chris
Hello Mike,
Mike wrote: This will not compile, since chart is type Steema.TeeChart.Chart, and the grid requires a System.Windows.UIElement.

How do I accomplish this?
Try:

Code: Select all

    private void InitializeChart()
    {
      RowDefinition chartRowDef = new RowDefinition();
      chartRowDef.Height = new GridLength(200);
      MyGrid.RowDefinitions.Add(chartRowDef);
      //...Create the chart
      Steema.TeeChart.WPF.TChart chart = new Steema.TeeChart.WPF.TChart();
      //...And add it to the grid control
      MyGrid.Children.Add(chart); //<--- WILL COMPILE! 
    }