如何将数据网格中的单元格内容居中? [英] How to center the content of cells in a data grid?
本文介绍了如何将数据网格中的单元格内容居中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我以这种方式设置了数据网格的最小高度:
I set the min height of a datagrid that way:
<DataGrid MinRowHeight="40">
在向数据网格提供数据后,每个单元格中的文本顶部和左对齐.我找不到一种简单的方法来使该文本居中.
After feeding the datagrid with datas, the text in each cell is top and left aligned. I could not find an easy way to center that text.
对此有什么建议吗?
推荐答案
最终解决方案:
<Style x:Key="DataGridContentCellCentering" 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>
这篇关于如何将数据网格中的单元格内容居中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文