1
votes

I would like to see in the group header of a datagrid some additional information per column. The header consists of a Stackpanel with some sub Stackpanels in it. Due to the fact that the user can adjust the size of the columns of the datagrid I have to adjust the size of the single header parts per binding the width of them to the width of the corresponding column:

 <ControlTemplate TargetType="{x:Type GroupItem}">
     <Expander IsExpanded="False">
         <Expander.Header>
             <StackPanel Orientation="Horizontal">
                  <StackPanel 
                       Orientation="Horizontal"
                       Width="{Binding Source={x:Reference TextCol01}, Path=ActualWidth}" >
                       <TextBlock Text="{Binding Path=Name}" />
                       <TextBlock Text=" ("/>
                       <TextBlock Text="{Binding Path=ItemCount}" FontSize="13" FontWeight="Bold"/>
                       <TextBlock Text=")"/>
                   </StackPanel>
                   <StackPanel 
                       Orientation="Horizontal">
                       <TextBlock Text="{Binding Path=Name}" />
                       <TextBlock Text=" ("/>
                       <TextBlock Text="{Binding Path=ItemCount}" FontSize="13" FontWeight="Bold"/>
                       <TextBlock Text=")"/>
                   </StackPanel>
                </StackPanel>
             </Expander.Header>
          <ItemsPresenter />
      </Expander>
  </ControlTemplate>

Without binding the Width (Width="{Binding Source={x:Reference TextCol01}, Path=ActualWidth}") the binding to the Name and the ItemCount of the CollectionViewGroup works perfect. But with binding the Width it fails.

I suppose it is to do with Binding Source. That changes the context or so. But I don't know what exactly is wrong with it.

Could anyone help? Thank you!

1
Sounds strange, the only thing that I can think of is that for some reason TextCol01 isn't there on load and the other bindings somehow don't get polled. - jimmyjambles
@jimmyjambles I'm calling the method to group the dataset after everything is loaded yet. So I think that could not be the problem. - manton

1 Answers

1
votes

I figured it out. This way to bind the width is working well:

Width="{Binding ElementName=TextCol01, Path=ActualWidth}"

this doesn't work:

Width="{Binding Source={x:Reference TextCol01}, Path=ActualWidth}"

It works standalone but together with the bindings of ItemCount and Name it leads to a failure.