WPF - DataGrid 列标题对齐
我正在使用 WPFToolkit DataGrid 控件,我想重新设置一些列标题的样式,以便标题文本垂直显示而不是水平显示(列中的数据都是数字,因此不是很宽,但标题文本是长的)。 因此,我创建了一个 DataTemplate 并尝试将 DataGridColumn.HeaderTemplate 获取到它。这是我的模板:
<DataTemplate x:Key="headerTemplate">
<StackPanel VerticalAlignment="Bottom" HorizontalAlignment="Left" Background="Aqua">
<StackPanel.LayoutTransform>
<RotateTransform Angle="-90"/>
</StackPanel.LayoutTransform>
<TextBlock Text="{Binding}" VerticalAlignment="Bottom" HorizontalAlignment="Left" Background="Pink">
</TextBlock>
</StackPanel>
</DataTemplate>
这工作得很好,除了标题的对齐方式始终是左对齐和居中。 StackPanel 或 TextBlock 的对齐组合似乎没有任何区别。我想让文本在底部和中间对齐。我怎样才能让它做到这一点?
谢谢,
AT
I'm using the WPFToolkit DataGrid control and I wanted to restyle some of the column headers so that the header text is displayed vertically instead of horizontally (the data in the column is all numeric and therefore, not very wide, but the header text is long).
So I created a DataTemplate to and tried to get the DataGridColumn.HeaderTemplate to it. This is my template:
<DataTemplate x:Key="headerTemplate">
<StackPanel VerticalAlignment="Bottom" HorizontalAlignment="Left" Background="Aqua">
<StackPanel.LayoutTransform>
<RotateTransform Angle="-90"/>
</StackPanel.LayoutTransform>
<TextBlock Text="{Binding}" VerticalAlignment="Bottom" HorizontalAlignment="Left" Background="Pink">
</TextBlock>
</StackPanel>
</DataTemplate>
This works just fine, except the alignment of the header is always left and center. No combination of alignments for the StackPanel or the TextBlock seems to make any difference. I would like to have the text aligned at the bottom and middle. How can I make it do that?
Thanks,
AT
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好的,找到答案了。
我正在寻找的属性是VerticalContentAlignment。
我创建了一个样式并使用 HeaderStyle 属性附加它,它起作用了:)
OK, found the answer.
The property I was looking for was VerticalContentAlignment.
I created a style and attached that using the HeaderStyle property, and it worked :)
如果您不想弄乱已经应用的样式,请使用 BasedOn:
If you don't want to mess up the style that you have already applied, use BasedOn:
这也可以添加
x:Key=""
如果您不想定位所有 DataGridColumnHeader,
This also works
Add the
x:Key=""
if you don't want to target all DataGridColumnHeader's