WPF DataGrid: ColumnHeaderStyle ContentTemplate is not shown in full height until after resizing

Dec 4, 2009 at 11:52 PM

 

This might be a bug in the WPF Toolkit DataGrid.
In my Windows.Resources I define the following ColumnHeaderStyle:
<Style x:Name="ColumnStyle" x:Key="ColumnHeaderStyle" TargetType="my:DataGridColumnHeader">
    <Setter Property="ContentTemplate">
        <Setter.Value>
            <DataTemplate>
                <StackPanel Orientation="Vertical">
                    <TextBlock Text="{Binding Name}" />
                    <TextBlock Text="{Binding Data}" />
                </StackPanel>
            </DataTemplate>
        </Setter.Value>
    </Setter>
</Style>
Because my columns are generated dynamically, I am defining the columns in code:
private void CreateColumn(Output output, int index)
{
    Binding textBinding = new Binding(string.Format("Relationships[{0}].Formula", index));
    DataGridTextColumn tc = new DataGridTextColumn();
    tc.Binding = textBinding;
    dg.Columns.Add(tc);
    tc.Header = output;
}
where Output is a simple class with Name and Data (string) properties.
What I observe is that only the Name property (first TextBlock control in the ContentTemplate's StackPanel) is shown. When I drag one of these column headers, I see the entire header (including the Data TextBlock). Only after manually resizing one of the columns are the column headers rendered correctly. Is there a way to get the column headers to show up correctly in code?

This might be a bug in the WPF Toolkit DataGrid.

In my Windows.Resources I define the following ColumnHeaderStyle:

<Style x:Name="ColumnStyle" x:Key="ColumnHeaderStyle" TargetType="my:DataGridColumnHeader">

    <Setter Property="ContentTemplate">

        <Setter.Value>

            <DataTemplate>

                <StackPanel Orientation="Vertical">

                    <TextBlock Text="{Binding Name}" />

                    <TextBlock Text="{Binding Data}" />

                </StackPanel>

            </DataTemplate>

        </Setter.Value>

    </Setter>

</Style>

 

Because my columns are generated dynamically, I am defining the columns in code:

 

private void CreateColumn(Output output, int index)

{

    Binding textBinding = new Binding(string.Format("Relationships[{0}].Formula", index));

    DataGridTextColumn tc = new DataGridTextColumn();

    tc.Binding = textBinding;

    dg.Columns.Add(tc);

    tc.Header = output;

}

where Output is a simple class with Name and Data (string) properties.

What I observe is that only the Name property (first TextBlock control in the ContentTemplate's StackPanel) is shown. When I drag one of these column headers, I see the entire header (including the Data TextBlock). Only after manually resizing one of the columns are the column headers rendered correctly. Is there a way to get the column headers to show up correctly in code?