我认为这取决于谁在数据网格中填充或停靠的面板水平内容对齐不适用于中心内容对齐您可以像这样使用 DataGrid.resource 标记
<DataGrid.Resources>
<Style TargetType="DataGridCell">
<Setter Property="HorizontalAlignment" Value="Center"/>
</Style>
<Style TargetType="DataGridColumnHeader">
<Setter Property="HorizontalContentAlignment" Value="Center"/>
</Style>
</DataGrid.Resources>
或者看这个
<DataGrid x:Name="DgvUsers" AutoGenerateColumns="False" IsReadOnly="True" EnableRowVirtualization="False"
HorizontalContentAlignment="Stretch" VerticalContentAlignment="Center" HeadersVisibility="Column"
IsTextSearchEnabled="True" FlowDirection="RightToLeft" SelectionMode="Single" FontFamily="/Sandogh.App;component/Font/#Lalezar" >
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="HorizontalAlignment" Value="Center"/>
</Style>
</DataGrid.CellStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="UserID" Visibility="Collapsed" Binding="{Binding Path=UserID}"/>
<DataGridTextColumn Header="FirstName" Binding="{Binding Path=Name}">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="HorizontalAlignment" Value="Center" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="LastName" Binding="{Binding Path=Family}"/>
<DataGridTextColumn Header="Gender" Binding="{Binding Path=TGender}"/>
<DataGridTextColumn Header="UserName" Binding="{Binding Path=UserName}"/>
<DataGridTextColumn Header="Password" Binding="{Binding Path=Password}"/>
<DataGridTextColumn Header="Activity" Binding="{Binding Path=TActivity}"/>
<DataGridTextColumn Header="JobID" Visibility="Collapsed" Binding="{Binding Path=JobID}"/>
<DataGridTextColumn Header="JobName" Binding="{Binding Path=JobName}"/>
</DataGrid.Columns>
</DataGrid>