TextBlock填充垂直空间

Dav*_*vid 2 wpf xaml transform textblock

我想创建一个TextBlock(或其他一些文本,其中仅显示文本)是垂直的(-90变换角度),但我希望该元素填充它所包含的垂直空间,但是具有定义的水平量(我使用垂直和水平术语而不是高度和宽度,因为当我有TextBlockgo垂直时它被交换),并且它与容器的左侧对齐.

我相信我理解如何TextBlock使用RenderTransform或使用LayoutTransform.然而,无论何时我改变容器的垂直方面,TextBlock水平方面而不是垂直方向的增加,我似乎无法使"对接"正常工作.

这是我有的:

<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="AttendanceTracker.StudentView"
x:Name="UserControl" Height="172.666" Width="417.333">

<StackPanel x:Name="LayoutRoot" Orientation="Horizontal">
    <Border BorderBrush="Black" BorderThickness="1" RenderTransformOrigin="0.5,0.5" Background="#52FFFFFF" Width="139.667">
        <TextBlock Text="My Title" TextWrapping="Wrap" FontSize="18.667" TextAlignment="Center" Foreground="White" Margin="-58.509,68.068,49.158,70.734" Background="Black" RenderTransformOrigin="0.5,0.5" Width="147.017" d:LayoutOverrides="Height">
            <TextBlock.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform Angle="-90"/>
                    <TranslateTransform/>
                </TransformGroup>
            </TextBlock.RenderTransform>
        </TextBlock>
    </Border>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)

更改UserControl的高度,您会注意到TextBlock水平方面的增加而不是所需的垂直方面.

Ken*_*art 6

如果我理解正确,那么这应该指向正确的方向:

<StackPanel Orientation="Horizontal">
    <TextBlock Background="Red" Text="My Title">
        <TextBlock.LayoutTransform>
            <TransformGroup>
                <RotateTransform Angle="90"/>
            </TransformGroup>
        </TextBlock.LayoutTransform>
    </TextBlock>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)

关键是要使用LayoutTransform,而不是RenderTransform.这将确保在转换发生后发生另一个布局传递.否则,布局系统使用原始边界矩形来布局TextBlock.

除此之外,我只是摆脱了所有Blend生成的残骸,看看发生了什么.这是结果:

alt text http://img187.imageshack.us/img187/1189/screenshottbv.png