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>

 

posted @ 2020-02-28 18:02  iDream2016  阅读(1256)  评论(0编辑  收藏  举报