TextBlock fills vertical space

I want to create TextBlock

(or some other element with text in it just for display) that is vertical (-90 angle angle), but I want that element to fill the vertical space it contains, but have a certain horizontal amount (I use vertical and horizontal words instead of height and width, as it swaps when I have TextBlock

go vertical) and align it with the left side of the container.

I believe I understand how to do it TextBlock

vertically using RenderTransform

or LayoutTransform

. However, I can't get the "docking" to work fine, whenever I change the vertical aspect of the container, it TextBlock

grows horizontally instead of vertically.

Here's what I have:

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

      

Change the height of the UserControl and you will notice that it TextBlock

grows in the horizontal aspect instead of the desired vertical aspect.

+2


source to share


1 answer


If I understand you correctly, this should point in the right direction:

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

      

The key is to use LayoutTransform

, not RenderTransform

. This ensures that a different layout happens after the conversion. Otherwise, the layout system uses the original bounding box for layout TextBlock

.



Other than that, I just got rid of all the Blend cruft I created to see what was going on. Here's the result:

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

+6


source







All Articles