title: WPF bind control width to ListBox column width
body: <p>I wrote XAML as follows:</p>
  
  <pre><code>&lt;UserControl.Resources&gt;
  
      &lt;GridViewColumnCollection x:Key="gvcc"&gt;
          &lt;GridViewColumn Header="Klient"
                    DisplayMemberBinding="{Binding CustomerName}"
                    Width="80"&gt;
          &lt;/GridViewColumn&gt;
          &lt;GridViewColumn Header="Budżet"
                    DisplayMemberBinding="{Binding Budget, StringFormat={}{0:C}}"
                    Width="80"&gt;
          &lt;/GridViewColumn&gt;
          &lt;GridViewColumn Header="Zysk. zakł."
                    DisplayMemberBinding="{Binding ExpectedProfability, StringFormat={}{0:C}}"
                    Width="80"&gt;
          &lt;/GridViewColumn&gt;
          &lt;GridViewColumn Header="Zysk. real."
                    DisplayMemberBinding="{Binding RealProfability, StringFormat={}{0:C}}"
                    Width="80"&gt;
          &lt;/GridViewColumn&gt;
          &lt;GridViewColumn Header="Miejsce"
                    DisplayMemberBinding="{Binding Place}"
                    Width="80" /&gt;
          &lt;GridViewColumn Header="Nr proj."
                    DisplayMemberBinding="{Binding Number}"
                    Width="80"&gt;
          &lt;/GridViewColumn&gt;
  
      &lt;/GridViewColumnCollection&gt;
  
  &lt;/UserControl.Resources&gt;
  
  ...
  
  &lt;Grid&gt;
          &lt;ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Visible"&gt;
              &lt;ItemsControl ItemsSource="{Binding GroupedProjects}"&gt;
                  &lt;ItemsControl.ItemTemplate&gt;
                      &lt;DataTemplate&gt;
                          &lt;Grid&gt;
                              &lt;Grid.RowDefinitions&gt;
                                  &lt;RowDefinition /&gt;
                                  &lt;RowDefinition /&gt;
                              &lt;/Grid.RowDefinitions&gt;
                              &lt;Grid.ColumnDefinitions&gt;
                                  &lt;ColumnDefinition Width="70" /&gt;
                                  &lt;ColumnDefinition Width="*" /&gt;
                              &lt;/Grid.ColumnDefinitions&gt;
  
                              &lt;Border Grid.Column="0" Grid.Row="0" Grid.RowSpan="3" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="Red" &gt;
                                  &lt;TextBlock FontSize="13" Text="{Binding Month}" TextAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center" /&gt;
                              &lt;/Border&gt;
  
                              &lt;GridViewHeaderRowPresenter Name="hrp" Columns="{StaticResource gvcc}" Grid.Column="1" Grid.Row="0" /&gt;
                              &lt;ListBox ItemsSource="{Binding Details}" Grid.Column="1" Grid.Row="1" ScrollViewer.VerticalScrollBarVisibility="Disabled"
                                       GotFocus="ListBox_GotFocus"
                                       PreviewMouseWheel="ListBox_PreviewMouseWheel"
                                       SelectedItem="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.SelectedProject}"&gt;
                                  &lt;ListBox.ItemTemplate&gt;
                                      &lt;DataTemplate&gt;
                                          &lt;GridViewRowPresenter Columns="{StaticResource gvcc}" Height="24" /&gt;
                                      &lt;/DataTemplate&gt;
                                  &lt;/ListBox.ItemTemplate&gt;
                              &lt;/ListBox&gt;
  &lt;!-- HERE IS THE PROBLEM --&gt;
                          &lt;/Grid&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/ItemsControl.ItemTemplate&gt;
                  &lt;ItemsControl.ItemsPanel&gt;
                      &lt;ItemsPanelTemplate&gt;
                          &lt;StackPanel Orientation="Vertical"/&gt;
                      &lt;/ItemsPanelTemplate&gt;
                  &lt;/ItemsControl.ItemsPanel&gt;
              &lt;/ItemsControl&gt;
          &lt;/ScrollViewer&gt;
      &lt;/Grid&gt;
  </code></pre>
  
  <p>Data are grouped in the ListBox, underneath the ListBox I want to display something like a summary row. I wanted to do this row as the StackPanel with TextBlock controls. The problem is - how to relate the width of the TextBox controls with the widths of columns in the ListBox.</p>
  
  <p>Let's say the "summary row" is something like that:</p>
  
  <pre><code>&lt;StackPanel Orientation="Horizontal"&gt;
  &lt;TextBlock Width="bind to ListBox.Column1.Width + ListBox.Column2.Width"&gt;some data&lt;/TextBlock&gt;
  &lt;TextBlock Width="bind to ListBox.Column3.Width"&gt;other data&lt;/TextBlock&gt;
  &lt;TextBlock Width="bind to ListBox.Column4.Width"&gt;etc.&lt;/TextBlock&gt;
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p>As you can see - first TextBlock width is something like "ColumnSpan = 2". The width of the other TextBlocks is simply the width of a column to which I would like to pair them.</p>
  
  <p>Is such a thing is even possible in XAML? Can anyone of you knows how to implement a similar solution in different way?</p>