0
votes

I got a simple question for all you friendly XAML experts. I have a datagrid with some row headers, which default horizontal alignment is center. All i want is to change this alignment to left. I have tried with the following code, but that dosent seem to work. Is it because the content consists of a textblock? If so, how do i get to change its alignment? I have tried changing the background of the header and it seems to work just fine.

Style:

<Style x:Key="DataGridRowHeaderStyle" TargetType="sdk:DataGridRowHeader">        
   <Setter Property="HorizontalContentAlignment" Value="Left"/>
</Style> 

Control:

<sdk:DataGrid x:Name="CheeseWeightsColumnStatsDataGrid"                           
              ItemsSource="{Binding CheeseWeightColumnStats}" IsReadOnly="True"              
              AutoGenerateColumns="False"
              HeadersVisibility="Row" 
              LoadingRow="CheeseWeightsColumnStatsDataGrid_OnLoadingRow" 
              RowHeaderStyle="{StaticResource DataGridRowHeaderStyle}">
</sdk:DataGrid>
1
I would have thought that everything inside the header would be aligned with the code you're using. But maybe you have to set the HorizontrolAlignment of the actual textblock, if this is created in code : 'textBlock.TextAlignment = TextAlignment.Left;'DNKROZ

1 Answers

0
votes

I would create a template for the row header and bind it to a property of the class that is displayed in the row:

  <sdk:DataGrid.RowHeaderTemplate>
    <DataTemplate>
      <TextBlock Text="{Binding HeaderText}" HorizontalAlignment="Left"/>
    </DataTemplate>
  </sdk:DataGrid.RowHeaderTemplate>