如何中心细胞在数据网格的内容? [英] How to center the content of cells in a data grid?
本文介绍了如何中心细胞在数据网格的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我设置一个DataGrid的最小高度方式:
I set the min height of a datagrid that way:
<DataGrid MinRowHeight="40">
与DATAS喂DataGrid中后,每个单元格中的文本是顶部和左对齐。 我无法找到一个简单的方法来居中文本。
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屋!
查看全文