DataGrid 字体垂直居中

如果用DataGridTextColumn作为DataGrid的列,字体垂直居中需要这样设置:

<Style x:Key="Body_Content_DataGrid_Centering"
     TargetType="{x:Type DataGridCell}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type DataGridCell}">
                <Grid Background="{TemplateBinding Background}">
                    <ContentPresenter VerticalAlignment="Center" />
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

标题水平居中这样设置:

<Style TargetType="DataGridColumnHeader">
       <Setter Property="HorizontalContentAlignment" Value="Center"/>
</Style>

猜你喜欢

转载自www.cnblogs.com/iDream2018/p/12378334.html