title: How to setup a grid as template for an Items control?
body: <p>I'm trying to create an <code>ItemsControl</code> that uses a grid as its <code>ItemsPanel</code> in such a way that it has two columns, where the first columns width is the width of the widest item in that column, and has as may rows needed to display all the items</p>
  
  <p>Basically, I want the following, but somehow within an <code>ItemsControl</code> so that I can bind to a collection of objects:</p>
  
  <pre><code>&lt;Grid&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="auto"/&gt;
              &lt;ColumnDefinition Width="*"/&gt;
          &lt;/Grid.ColumnDefinitions&gt;
  
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="auto"/&gt;
              &lt;RowDefinition Height="auto"/&gt;
              &lt;RowDefinition Height="auto"/&gt;
          &lt;/Grid.RowDefinitions&gt;
  
          &lt;Label Content="{Binding Items[0].Header}"/&gt;
          &lt;TextBox Text="{Binding Items[0].Content}" Grid.Column="1"/&gt;
  
          &lt;Label Content="{Binding Items[1].Header}" Grid.Row="1"/&gt;
          &lt;TextBox Text="{Binding Items[1].Content}" Grid.Row="1" Grid.Column="1"/&gt;
  
          &lt;Label Content="{Binding Items[2].Header}" Grid.Row="2"/&gt;
          &lt;TextBox Text="{Binding Items[2].Content}" Grid.Row="2" Grid.Column="1"/&gt;
      &lt;/Grid&gt; 
  </code></pre>
  
  <p>Edit : Rachels answer worked great, here is a working example.</p>
  
  <p>(I moved the Grid.IsSharedSizeScope="True" to the ItemsPanel, not sure if Rachel meant to put it in the ItemTemplate (which didn't work))</p>
  
  <pre><code>namespace WpfApplication23
  {
      public partial class Window1 : Window
      {
          public List&lt;Item&gt; Items { get; set; }
  
          public Window1()
          {
              Items = new List&lt;Item&gt;() 
              { 
                  new Item(){ Header="Item0", Content="someVal" },
                  new Item(){ Header="Item1", Content="someVal" },
                  new Item(){ Header="Item267676", Content="someVal" },
                  new Item(){ Header="a", Content="someVal" },
                  new Item(){ Header="bbbbbbbbbbbbbbbbbbbbbbbbbb", Content="someVal" },
                  new Item(){ Header="ccccccc", Content="someVal" } 
              };
  
              InitializeComponent();
  
              DataContext = this;
          }
      }
  
      public class Item
      {
          public string Header { get; set; }
          public string Content { get; set; }
      }
  }
  
  &lt;Window x:Class="WpfApplication23.Window1"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
  
      &lt;ItemsControl ItemsSource="{Binding Items}"&gt;
  
          &lt;ItemsControl.ItemsPanel&gt;
              &lt;ItemsPanelTemplate&gt;
                  &lt;StackPanel Grid.IsSharedSizeScope="True"/&gt;
              &lt;/ItemsPanelTemplate&gt;
          &lt;/ItemsControl.ItemsPanel&gt;
  
          &lt;ItemsControl.ItemTemplate&gt;
              &lt;DataTemplate&gt;
                  &lt;Grid&gt;
                      &lt;Grid.ColumnDefinitions&gt;
                          &lt;ColumnDefinition SharedSizeGroup="ColumnOne" /&gt;
                          &lt;ColumnDefinition Width="*" /&gt;
                      &lt;/Grid.ColumnDefinitions&gt;
                      &lt;Label Content="{Binding Header}"/&gt;
                      &lt;TextBox Text="{Binding Content}" Grid.Column="1"/&gt;
                  &lt;/Grid&gt;
              &lt;/DataTemplate&gt;
          &lt;/ItemsControl.ItemTemplate&gt;
      &lt;/ItemsControl&gt;
  &lt;/Window&gt;
  </code></pre>