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>
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.