title: WPF Table Column Sizes
body: <p>I'm rendering a <a href="http://msdn.microsoft.com/en-us/library/system.windows.documents.table.aspx" rel="noreferrer">Table</a> in a WPF <a href="http://msdn.microsoft.com/en-us/library/system.windows.documents.flowdocument.aspx" rel="noreferrer">FlowDocument</a> using code-behind. But, I've been unable to find an example that shows how to make the table use only the space needed <a href="http://msdn.microsoft.com/en-us/library/system.windows.gridlength.aspx" rel="noreferrer">based on content</a>.  Instead the table takes up all available width, which I don't want, nor do I want to have to specify a exact pixel sizes.</p>
  
  <p>I'm clearly missing something simple, anyone see it?</p>
  
  <pre><code>var fd = new FlowDocument();
  
  Table t = new Table();
  
  t.BorderBrush = Brushes.Black;
  t.BorderThickness = new Thickness(2);
  
  // I thought this would do what I wanted...
  t.Columns.Add(new TableColumn() { Width = GridLength.Auto });
  t.Columns.Add(new TableCOlumn() { Width = GridLength.Auto });
  
  TableRowGroup trg = new TableRowGroup();
  
  TableRow currentRow = new TableRow();
  currentRow.Cells.Add(new TableCell(new Paragraph(new Run("ABC"))));
  currentRow.Cells.Add(new TableCell(new Paragraph(new Run("XYZ"))));
  trg.Rows.Add(currentRow);
  
  currentRow = new TableRow();
  currentRow.Cells.Add(new TableCell(new Paragraph(new Run("123"))));
  currentRow.Cells.Add(new TableCell(new Paragraph(new Run("789"))));
  trg.Rows.Add(currentRow);
  
  t.RowGroups.Add(trg);
  
  fd.Blocks.Add(t);
  </code></pre>