如何在WPF DataGrid的列标题中设置垂直文本? [英] How to set vertical text in the column headers of WPF DataGrid?

查看:203
本文介绍了如何在WPF DataGrid的列标题中设置垂直文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗯,实际上是我从水平方向旋转了-90度。

Well, actually rotated -90 degrees from horizontal is what I mean.

我需要这样做,因为标题的文本很长,但是单元格的值很短,并且我想在屏幕上容纳很多列。

I need to do this because the text for the header is quite long but the cell value is short, and I want to fit a lot of columns on the screen.

是否可以轻松地做到这一点,还是我需要首先了解资源和模板?我不介意 hack解决方案!

Is it possible to do this easily or do I need to learn about resources and templates first? I don't mind a "hack" solution!

推荐答案

这将旋转整个ColumnHeaderCell:

This will rotate the whole ColumnHeaderCell:

<DataGrid.ColumnHeaderStyle>
    <Style TargetType="{x:Type DataGridColumnHeader}">
        <Setter Property="LayoutTransform">
            <Setter.Value>
                <RotateTransform Angle="270" />
            </Setter.Value>
        </Setter>
    </Style>
</DataGrid.ColumnHeaderStyle>

请注意:这意味着 Horizo​​ntalContentAlignment VerticalContentAlignment ,反之亦然。

Be aware: this means HorizontalContentAlignment is then a VerticalContentAlignment and vice versa.

这篇关于如何在WPF DataGrid的列标题中设置垂直文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆