title: How to center a TextBlock within a CellTemplate in WPF?
body: <p>I tried both <code>HorizontalAlignment</code> and <code>TextAlignment</code> but it has no effect.</p>
  
  <pre><code>&lt;GridViewColumn Width="Auto" Header="Type"&gt;
      &lt;GridViewColumn.CellTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;TextBlock Text="{Binding Type}" HorizontalAlignment="Center"  TextAlignment="Center" /&gt;
          &lt;/DataTemplate&gt;
      &lt;/GridViewColumn.CellTemplate&gt;
  &lt;/GridViewColumn&gt;
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>EDIT:</p>
  
  <p>Xaml code:</p>
  
  <pre><code>&lt;Window x:Class="EffectsWindow.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="Effects Editor"
      &lt;DockPanel VerticalAlignment="Stretch"&gt;
          &lt;DockPanel.Resources&gt;
  
          &lt;ListView
                    DockPanel.Dock="Top"
                    HorizontalContentAlignment="Stretch"
                    ItemsSource="{Binding EditorViewModel.AllEffects}"&gt;
  
              &lt;ListView.View&gt;
                  &lt;GridView&gt;
                      &lt;GridViewColumn Width="Auto"
                                      DisplayMemberBinding="{Binding Name}"
                                      Header="Name" /&gt;
  
                      &lt;GridViewColumn Width="Auto" Header="Type"&gt;
                          &lt;GridViewColumn.CellTemplate&gt;
                              &lt;DataTemplate&gt;
                                  &lt;TextBlock Text="{Binding Type}" HorizontalAlignment="Center"  TextAlignment="Center" /&gt;
                              &lt;/DataTemplate&gt;
                          &lt;/GridViewColumn.CellTemplate&gt;
                      &lt;/GridViewColumn&gt;
  
                  &lt;/GridView&gt;
              &lt;/ListView.View&gt;
          &lt;/ListView&gt;
  
          &lt;DockPanel Width="100"
                     Height="100"
                     Margin="0,0,20,20"
                     HorizontalAlignment="Right"
                     VerticalAlignment="Bottom"&gt;
  
              &lt;Label Margin="0,0,0,0"
                     Content="Data"
                     DockPanel.Dock="Top" /&gt;
  
              &lt;ListBox
                       VerticalAlignment="Top"/&gt;
  
          &lt;/DockPanel&gt;
  
      &lt;/DockPanel&gt;
  &lt;/Window&gt;
  </code></pre>