title: Dynamically add Columns to DataGrid in wpf
body: <p>I am currently working on a custom canvas and in that i have to add a table,So i thought dataGrid would be fine. SO i Want to create a "<strong>Table"</strong> from <strong>"Datagrid"</strong> by which user can add a table to the canvas at runtime.</p>
  
  <p>Till now,  I have tried to Populate DataGrid With a list and succeded.</p>
  
  <p>How Can I add Columns to a Datagrid at runtime,such that the number of columns and header value Would be taken from  the user  at runtime using a textbox and based on the value of the textbox the datagrid should add columns and header value.</p>
  
  <p>Actually I want to develop a Table in which user passes the no of columns and the column header and the table should be generated.</p>
  
  <p>Or </p>
  
  <p><strong>"Can you suggest me with a way where i should look in order to to "Draw" a Table using DrawingVisual class"</strong></p>
  
  <p>It is a part of GraphicsTable Class</p>
  
  <pre><code>//Custom Classes "DrawingCanvas &amp; GraphicsTable" 
  public void CreateDataGrid(GraphicsTable graphicsTable, DrawingCanvas drawingCanvas)
  {
      dt = new DataGrid();
      dt.Name = "Data";
      dt.ItemsSource = person();
      dt.AllowDrop = true;
      dt.AutoGenerateColumns = true;
      dt.Height = graphicsTable.Rectangle.Height;
      dt.Width = graphicsTable.Rectangle.Width;
      drawingCanvas.Children.Add(dt);
      Canvas.SetTop(dt, graphicsTable.Rectangle.Top);
      Canvas.SetLeft(dt, graphicsTable.Rectangle.Left);
      dt.Width = dt.Width;
      dt.Height = dt.Height;
      dt.Focus();
  }
  //I have just tried to add dome dummy data to the datagrid.
  
  public List&lt;Person&gt; person()
  {
      List&lt;Person&gt; peep = new List&lt;Person&gt;();
      peep.Add(new Person() {});
      return peep;
  }
  
  public class Person
  {
      private string name;
      private double salary;
      public string Names
      {
          get { return name; }
          set { name = value; }
      }
      public double Salary
      {
          get { return salary; }
          set { salary = value; }
      }
  }
  </code></pre>