2009-08-26 158 views
2

我想要創建一個垂直(-90變換角度)的TextBlock(或一些其他文本僅用於顯示的元素),但我希望該元素填充它包含的垂直空間中,但有一個定義的水平量(我使用垂直和水平項而不是高度和寬度,因爲當我將TextBlock垂直移動時它會被交換),並將它對齊到容器的左側。TextBlock填充垂直空間

我相信我明白如何使TextBlock垂直使用RenderTransformLayoutTransform。然而,我似乎無法讓「對接」正常工作,只要我改變容器的垂直方向,水平方向而不是垂直方向增加。

以下是我有:在用戶控件的

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

變化的高度,你會發現,TextBlock增加水平方面,而不是所需的垂直方面。

回答

6

如果我理解正確的話,那麼這個應該指向你在正確的方向:

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

的關鍵是使用LayoutTransform,不RenderTransform。這將確保在轉換髮生後發生另一個佈局傳遞。否則,佈局系統將使用原始的邊界矩形來佈局TextBlock

除此之外,我只是擺脫了所有Blend生成的cruft,看看發生了什麼。結果如下:

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