title: TextBlock text not vertically centering within DataGridCell
body: <p>I'm creating a <code>DataGrid</code> in C# (from code-behind/not XAML), but no matter what I try, I can't get the text to be vertically center in the data cells:</p>
  
  <p><img src="https://i.stack.imgur.com/hu7Rlm.png" alt="]"></p>
  
  <p>I started off with:</p>
  
  <pre><code>var CellStyle = new Style(typeof(DataGridCell)) {
      Setters = {
          new Setter(TextBlock.TextAlignmentProperty, TextAlignment.Center)
      }
  };
  </code></pre>
  
  <p>Which correctly targets the cell and horizontally centres the text (per the screenshot above).</p>
  
  <p>Trying to vertically center the text, I know that a <code>TextBlock</code> doesn't support vertical content alignment, only its own vertical alignment within a parent element.</p>
  
  <p>Per this question (<a href="https://stackoverflow.com/questions/1491649/text-vertical-alignment-in-wpf-textblock">Text vertical alignment in WPF TextBlock</a>) I tried to fake it using <code>Padding</code>:</p>
  
  <pre><code>var CellStyle = new Style(typeof(DataGridCell)) {
      Setters = {
          new Setter(TextBlock.PaddingProperty, new Thickness(5)),
          new Setter(TextBlock.TextAlignmentProperty, TextAlignment.Center)
      }
  };
  </code></pre>
  
  <p>This made no difference. Then I tried this:</p>
  
  <pre><code>var CellStyle = new Style(typeof(DataGridCell)) {
      Setters = {
          new Setter(DataGridCell.VerticalContentAlignmentProperty, VerticalAlignment.Center),
          new Setter(TextBlock.TextAlignmentProperty, TextAlignment.Center),
          new Setter(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center)
      }
  };
  </code></pre>
  
  <p>Which resulted in:</p>
  
  <p><img src="https://i.imgur.com/fLx3K4om.png" alt=""></p>
  
  <p>Adding <code>new Setter(DataGridCell.HeightProperty, 50d),</code> results in screenshot #1.</p>
  
  <p>How can I vertically center the text in my data cells?</p>