代码之家  ›  专栏  ›  技术社区  ›  David

文本块填充垂直空间

  •  2
  • David  · 技术社区  · 17 年前

    我想创建一个 TextBlock (或其他元素,其中包含文本仅用于显示)这是垂直的(-90变换角度),但我希望该元素填充其包含的垂直空间,但具有定义的水平量(我使用垂直和水平项,而不是高度和宽度,因为当我有 控件

    我相信我知道如何做一个 控件 垂直使用 RenderTransform LayoutTransform . 然而,每当我改变容器的垂直方向时,我似乎无法使“停靠”正常工作 在水平方向而不是垂直方向上增加。

    以下是我所拥有的:

    <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>
    

    更改UserControl的高度,您会注意到 控件 在水平方向而不是所需的垂直方向上增加。

    1 回复  |  直到 14 年前
        1
  •  6
  •   Tim Cooper    14 年前

    如果我理解正确,那么这将为您指明正确的方向:

    <StackPanel Orientation="Horizontal">
        <TextBlock Background="Red" Text="My Title">
            <TextBlock.LayoutTransform>
                <TransformGroup>
                    <RotateTransform Angle="90"/>
                </TransformGroup>
            </TextBlock.LayoutTransform>
        </TextBlock>
    </StackPanel>
    

    关键是使用 LayoutTransform RenderTransform TextBlock

    除此之外,我刚刚去除了所有混合生成的积垢,看看发生了什么。结果如下:

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