title: How to add columns to a DataGrid?
body: <p>I'm basing myself on <a href="http://stackoverflow.com/questions/20770438">this other question</a> to show a DataGrid with some columns (no rows to be populated yet, just the columns):</p>
  <p>I have following source code:</p>
  <h2>cs file:</h2>
  <pre><code>public partial class MainWindow : Window
  {
      private DataTable dt_main;
      ...
  }
  
  private ...first_Click(object sender, ...)
  {
      dt_main = new DataTable(&quot;dt_main&quot;); // just a default name, no such table
      DataGrid1.DataContext = dt_main.DefaultView;
  }
  
  private ...second_Click(object sender, ...)
  {
      dt_main.Columns.Clear();
      ...
      while (...)
        dt_main.Columns.Add(tmp_ColName);
  }
  </code></pre>
  <h2>XAML file:</h2>
  <pre><code>&lt;DataGrid x:Name=&quot;DataGrid1&quot; ... AutoGenerateColumns=&quot;True&quot; ItemsSource=&quot;{Binding}&quot;/&gt;
  </code></pre>
  <p>I click on the <code>first_click</code> (this is for filling the list of tables) and then on <code>second_click</code> (this is for choosing the table), but although the DataTable's <code>Columns</code> attribute is filled in, I see nothing in my DataGrid, as you can see in following screenshot (the DataGrid is shown by the red arrow):</p>
  <p><a href="https://i.stack.imgur.com/C7qJ0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/C7qJ0.png" alt="screenshot" /></a></p>
  <p>Does anybody know what I'm missing?</p>