title: WPF DataGrid: ColumnHeaderStyle ContentTemplate is not shown in full height until after resizing
body: <p>This might be a bug in the WPF Toolkit <code>DataGrid</code>.</p>
  
  <p>In my Windows.Resources I define the following <code>ColumnHeaderStyle</code>:</p>
  
  <pre><code>&lt;Style x:Name="ColumnStyle" x:Key="ColumnHeaderStyle" TargetType="my:DataGridColumnHeader"&gt;
      &lt;Setter Property="ContentTemplate"&gt;
          &lt;Setter.Value&gt;
              &lt;DataTemplate&gt;
                  &lt;StackPanel Orientation="Vertical"&gt;
                      &lt;TextBlock Text="{Binding Name}" /&gt;
                      &lt;TextBlock Text="{Binding Data}" /&gt;
                  &lt;/StackPanel&gt;
              &lt;/DataTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>Because my columns are generated dynamically, I am defining the columns in code:</p>
  
  <pre><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;
  }
  </code></pre>
  
  <p>where <code>Output</code> is a simple class with <code>Name</code> and <code>Data</code> (string) properties.</p>
  
  <p>What I observe is that <strong>only the Name property</strong> (first <code>TextBlock</code> control in the <code>ContentTemplate</code>'s <code>StackPanel</code>) <strong>is shown</strong>. When I drag one of these column headers, I see the entire header (including the Data <code>TextBlock</code>). Only <strong>after manually resizing one of the columns are the column headers rendered correctly</strong>. Is there a way to get the column headers to show up correctly in code?</p>
  
  <p><strong>Update:</strong> as requested, here is the rest of my code for the repro.</p>
  
  <pre><code>public class Input
  {
      public Input() 
      {
          Relationships = new ObservableCollection&lt;Relationship&gt;();
      }
  
      public string Name { get; set; }
      public string Data { get; set; }
  
      public ObservableCollection&lt;Relationship&gt; Relationships { get; set; }
  }
  
  public class Output
  {
      public Output() { }
  
      public string Name { get; set; }
      public string Data { get; set; }
  }
  
  public class Relationship
  {
      public Relationship() { }
  
      public string Formula { get; set; }
  }
  </code></pre>
  
  <p>Here is the XAML markup:</p>
  
  <pre><code>&lt;Window x:Class="GridTest.Window1"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="Window1" Height="300" Width="300" xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit"&gt;
      &lt;Window.Resources&gt;
          &lt;SolidColorBrush x:Key="RowHeaderIsMouseOverBrush" Color="Red" /&gt;
          &lt;SolidColorBrush x:Key="RowBackgroundSelectedBrush" Color="Yellow" /&gt;
          &lt;BooleanToVisibilityConverter x:Key="bool2VisibilityConverter" /&gt;
  
          &lt;Style x:Key="RowHeaderGripperStyle" TargetType="{x:Type Thumb}"&gt;
              &lt;Setter Property="Height" Value="2"/&gt;
              &lt;Setter Property="Background" Value="Green"/&gt;
              &lt;Setter Property="Cursor" Value="SizeNS"/&gt;
              &lt;Setter Property="Template"&gt;
                  &lt;Setter.Value&gt;
                      &lt;ControlTemplate TargetType="{x:Type Thumb}"&gt;
                          &lt;Border Padding="{TemplateBinding Padding}"
                  Background="{TemplateBinding Background}"/&gt;
                      &lt;/ControlTemplate&gt;
                  &lt;/Setter.Value&gt;
              &lt;/Setter&gt;
          &lt;/Style&gt;
  
          &lt;Style x:Name="ColumnStyle" x:Key="ColumnHeaderStyle" TargetType="my:DataGridColumnHeader"&gt;
              &lt;Setter Property="ContentTemplate"&gt;
                  &lt;Setter.Value&gt;
                      &lt;DataTemplate&gt;
                          &lt;StackPanel Orientation="Vertical"&gt;
                              &lt;TextBlock Text="{Binding Name}" /&gt;
                              &lt;TextBlock Text="{Binding Data}" /&gt;
                          &lt;/StackPanel&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/Setter.Value&gt;
              &lt;/Setter&gt;
          &lt;/Style&gt;
  
          &lt;!-- from http://www.codeplex.com/wpf/WorkItem/View.aspx?WorkItemId=9193 --&gt;
          &lt;Style x:Name="RowHeaderStyle" x:Key="RowHeaderStyle" TargetType="my:DataGridRowHeader"&gt;
              &lt;Setter Property="Content" Value="{Binding}" /&gt;
              &lt;Setter Property="ContentTemplate"&gt;
                  &lt;Setter.Value&gt;
                      &lt;DataTemplate&gt;
                          &lt;StackPanel Orientation="Horizontal"&gt;
                              &lt;TextBlock Text="{Binding Path=Content.Name, RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type my:DataGridRowHeader}}}" 
                                         VerticalAlignment="Center"/&gt;
                              &lt;TextBlock Padding="5"&gt;|&lt;/TextBlock&gt;
                              &lt;TextBlock Text="{Binding Path=Content.Data, RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type my:DataGridRowHeader}}}"
                                         VerticalAlignment="Center"/&gt;
                          &lt;/StackPanel&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/Setter.Value&gt;
              &lt;/Setter&gt;
          &lt;/Style&gt;
  
          &lt;DataTemplate x:Key="CellTemplate"&gt;
              &lt;StackPanel&gt;
                  &lt;TextBox Text="{Binding Formula, Mode=TwoWay}" /&gt;
              &lt;/StackPanel&gt;
          &lt;/DataTemplate&gt;
  
          &lt;DataTemplate x:Key="CellEditTemplate"&gt;
              &lt;StackPanel&gt;
                  &lt;TextBox Text="{Binding Formula, Mode=TwoWay}" /&gt;
              &lt;/StackPanel&gt;
          &lt;/DataTemplate&gt;
  
      &lt;/Window.Resources&gt;
      &lt;Grid&gt;
          &lt;my:DataGrid Name="dg" 
                       ColumnHeaderStyle="{StaticResource ColumnHeaderStyle}"
                       RowHeaderStyle="{StaticResource RowHeaderStyle}"
                       HeadersVisibility="All" /&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>And finally the code-behind:</p>
  
  <pre><code>/// &lt;summary&gt;
  /// Interaction logic for Window1.xaml
  /// &lt;/summary&gt;
  public partial class Window1 : Window
  {
      public Window1()
      {
          InitializeComponent();
          Inputs = new List&lt;Input&gt;();
          Outputs = new List&lt;Output&gt;();
  
          Input i1 = new Input() { Name = "I 1", Data = "data 1" };
          Input i2 = new Input() { Name = "I 2", Data = "data 2" };
  
  
          Inputs.Add(i1); Inputs.Add(i2);
  
          Output o1 = new Output() { Name = "O 1", Data = "data 1" };
          Output o2 = new Output() { Name = "O 2", Data = "data 2" };
          Output o3 = new Output() { Name = "O 3", Data = "data 3" };
  
          Outputs.Add(o1); Outputs.Add(o2); Outputs.Add(o3);
  
          Relationship r1 = new Relationship() { Formula = "F1" };
          Relationship r2 = new Relationship() { Formula = "F2" };
          Relationship r3 = new Relationship() { Formula = "F3" };
          Relationship r4 = new Relationship() { Formula = "F4" };
  
          i1.Relationships.Add(r1);
          i1.Relationships.Add(r2);
          i2.Relationships.Add(r3);
          i2.Relationships.Add(r4);
  
  
          CreateColumn(o1, 0);
          CreateColumn(o2, 1);
          CreateColumn(o3, 2);
  
          dg.Items.Add(i1);
          dg.Items.Add(i2);
          dg.ColumnWidth = DataGridLength.SizeToHeader;
      }
  
      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;
      }
  
      private List&lt;Output&gt; Outputs { get; set; }
      private List&lt;Input&gt; Inputs { get; set; }
  }
  </code></pre>