title: WPF Grid.IsSharedSizeScope between two parent controls?
body: <p>I have a situation where I need to share the width of a column between grids in two group boxes, the XAML looks something like this:</p>
  
  <pre><code>&lt;GroupBox Header="Box A"&gt;
          &lt;StackPanel Orientation="Horizontal"&gt;
              &lt;!-- Labels --&gt;
              &lt;Grid&gt;
                  &lt;Grid.ColumnDefinitions&gt;
                      &lt;ColumnDefinition SharedSizeGroup="Labels"&gt;&lt;/ColumnDefinition&gt;
                  &lt;/Grid.ColumnDefinitions&gt;
                  &lt;Grid.RowDefinitions&gt;
                      &lt;RowDefinition SharedSizeGroup="Rows"&gt;&lt;/RowDefinition&gt;
                  &lt;/Grid.RowDefinitions&gt;
  
                  &lt;Label Grid.Column="0" Grid.Row="0"&gt;Label A&lt;/Label&gt;
              &lt;/Grid&gt;
  
              &lt;!-- Fields --&gt;
              &lt;ItemsControl Grid.IsSharedSizeScope="True" ItemsSource="{Binding Items}"&gt;
                  &lt;ItemsControl.ItemsPanel&gt;
                      &lt;ItemsPanelTemplate&gt;
                          &lt;StackPanel Orientation="Horizontal"&gt;&lt;/StackPanel&gt;
                      &lt;/ItemsPanelTemplate&gt;
                  &lt;/ItemsControl.ItemsPanel&gt;
                  &lt;ItemsControl.ItemTemplate&gt;
                      &lt;DataTemplate&gt;
                          &lt;Grid&gt;
                              &lt;Grid.RowDefinitions&gt;
                                  &lt;RowDefinition SharedSizeGroup="Rows"&gt;&lt;/RowDefinition&gt;
                              &lt;/Grid.RowDefinitions&gt;
  
                              &lt;TextBox Text="{Binding PropertyA}"&gt;&lt;/TextBox&gt;
                          &lt;/Grid&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/ItemsControl.ItemTemplate&gt;
              &lt;/ItemsControl&gt;
          &lt;/StackPanel&gt;
      &lt;/GroupBox&gt;
  
      &lt;GroupBox Header="Box B"&gt;
          &lt;StackPanel Orientation="Horizontal"&gt;
              &lt;!-- Labels --&gt;
              &lt;Grid&gt;
                  &lt;Grid.ColumnDefinitions&gt;
                      &lt;ColumnDefinition SharedSizeGroup="Labels"&gt;&lt;/ColumnDefinition&gt;
                  &lt;/Grid.ColumnDefinitions&gt;
                  &lt;Grid.RowDefinitions&gt;
                      &lt;RowDefinition SharedSizeGroup="Rows"&gt;&lt;/RowDefinition&gt;
                  &lt;/Grid.RowDefinitions&gt;
  
                  &lt;Label Grid.Column="0" Grid.Row="0"&gt;Label B&lt;/Label&gt;
              &lt;/Grid&gt;
  
              &lt;!-- Fields --&gt;
              &lt;ItemsControl Grid.IsSharedSizeScope="True" ItemsSource="{Binding Items}"&gt;
                  &lt;ItemsControl.ItemsPanel&gt;
                      &lt;ItemsPanelTemplate&gt;
                          &lt;StackPanel Orientation="Horizontal"&gt;&lt;/StackPanel&gt;
                      &lt;/ItemsPanelTemplate&gt;
                  &lt;/ItemsControl.ItemsPanel&gt;
                  &lt;ItemsControl.ItemTemplate&gt;
                      &lt;DataTemplate&gt;
                          &lt;Grid&gt;
                              &lt;Grid.RowDefinitions&gt;
                                  &lt;RowDefinition SharedSizeGroup="Rows"&gt;&lt;/RowDefinition&gt;
                              &lt;/Grid.RowDefinitions&gt;
  
                              &lt;TextBox Text="{Binding PropertyB}"&gt;&lt;/TextBox&gt;
                          &lt;/Grid&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/ItemsControl.ItemTemplate&gt;
              &lt;/ItemsControl&gt;
          &lt;/StackPanel&gt;
      &lt;/GroupBox&gt;
  </code></pre>
  
  <p>I have tried setting Grid.IsSharedSizeScope to true on both the StackPanel and GroupBox containing the child grids, but this did not work. I was wondering what approach I should take in this situation to share the size between the Grid column definitions with the SharedSizeGroup of 'Labels'?</p>
  
  <p>Thanks,</p>
  
  <p>Alex.</p>