title: Center text using Synchfusion's SfDataGrid for UWP with dynamic columns
body: <p>I am trying to center the text in the cells for a SfDataGrid in UWP. The columns are bound during runtime so I can not set a cell style on column elements.</p>
  
  <p>The xaml for the grid looks like this:</p>
  
  <pre><code>                  &lt;grid:SfDataGrid Name="GridData"
                                       AlternatingRowStyle="{StaticResource mainTableRowStyle}"
                                       RowStyle="{StaticResource mainTableRowStyle}"
                                       HeaderStyle="{StaticResource headerStyle}"
                                       Foreground="WhiteSmoke"
                                       framework:FocusExtension.IsFocused="{Binding Focused}"
                                       AllowSelectionOnPointerPressed="True"
                                       Grid.Row="0"
                                       Columns="{Binding SfGridColumns, Mode=TwoWay}"
                                       AutoGenerateColumns="True"
                                       IsDynamicItemsSource="True"
                                       ItemsSource="{Binding ElementName=dataPager,Path=PagedSource}"
                                       ColumnSizer="Star"
                                       AllowSorting="False"
                                       SelectedItem="{Binding SelectedGridItem, Mode =TwoWay, UpdateSourceTrigger=PropertyChanged}"&gt;
                          &lt;interactivity:Interaction.Behaviors&gt;
                              &lt;core:EventTriggerBehavior EventName="Holding"&gt;
                                  &lt;core:InvokeCommandAction Command="{Binding HoldCommand}" /&gt;
                              &lt;/core:EventTriggerBehavior&gt;
                          &lt;/interactivity:Interaction.Behaviors&gt;
                      &lt;/grid:SfDataGrid&gt;
  </code></pre>
  
  <p>I have tried to add a style to the cells in order to align the text:</p>
  
  <pre><code>    &lt;Style x:Key="cellStyle" TargetType="grid:GridCell"&gt;
          &lt;Setter Property="FontSize" Value="20" /&gt;
          &lt;Setter Property="HorizontalAlignment" Value="Center"/&gt;
          &lt;Setter Property="FontWeight" Value="Bold" /&gt;
      &lt;/Style&gt;
     &lt;!-- CellStyle="{StaticResource cellStyle}" --&gt;
  </code></pre>
  
  <p>But that doesn't help because it centers the entire cell and the inner borders of the grid are disrupted. (looks something like the below picture)</p>
  
  <p><a href="https://i.stack.imgur.com/rbP6X.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rbP6X.png" alt="enter image description here"></a></p>
  
  <p>I want just the text inside the cell to be aligned. (also tried the HorizontalContentAlignment center, it didn't do anything)</p>
  
  <p>Finally, I have tried to rewrite the template of the cell. The SfDataGrid does not have a CellTemplate property, but it has a GridCellTemplateSelector property. So, I have created a template like this:</p>
  
  <pre><code>    &lt;framework:GridCellTemplateSelector x:Key="templateSelector"/&gt;
      &lt;DataTemplate x:Key="CellTemplate1"&gt;
          &lt;TextBlock Foreground="DarkBlue" Text="{Binding}" HorizontalAlignment="Center"/&gt;
      &lt;/DataTemplate&gt; &lt;!-- and added CellTemplateSelector="{StaticResource templateSelector}" to the grid --&gt;
  
  public class GridCellTemplateSelector : DataTemplateSelector
      {
      protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
          {
              return Application.Current.Resources["CellTemplate1"] as DataTemplate;
          }
      }
  </code></pre>
  
  <p>This one doesn't work also because it seems the method in GridCellTemplateSelector is not hit. I am thinking if I could make the CellTemplateSelector to work I could achieve my objective.</p>