42

I want to have an text vertical. I just use a simple grid in WPF to auto-size the areas. But when using RotateTransform, all calculations are wrong. Any idea how to solve this?

        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

WPF rotate text In this image you see what I mean. If I now want to auto-size the middle part I cannot use "Width" or "Height" property because both will raise a wrong sizing result. Width =120px will increase the horicontal (original) width and will make the complete row 120pixel. Height=120px will make the text 120pixel height.

3 Answers 3

88

Use a LayoutTransform instead of a RenderTransform. It gets applied during the layout pass, not during rendering.

2
  • In Blend, this is somewhat "below the fold" -- meaning that you see RenderTransform by default and have to expand the Transforms panel to see LayoutTransform. I'd never noticed it there, but sure enough it's hiding in almost plain sight.
    – Mike L
    Oct 24, 2012 at 14:30
  • @Rachel Can UWP use the LayoutTransform?
    – quangkid
    Nov 28, 2017 at 8:39
39

Like Rachel said use LayoutTransform

<TextBlock Text="Goodday" >
   <TextBlock.LayoutTransform>
     <RotateTransform Angle="90" />
   </TextBlock.LayoutTransform>  
</TextBlock>
1
<TextBlock Height="14" 
    x:Name="TextBlock1" 
    Text="Vertical Bottom to Up" Margin="73,0,115,0" RenderTransformOrigin="0.5,0.5" > 
    <TextBlock.RenderTransform> 
        <TransformGroup> 
            <ScaleTransform/> 
            <SkewTransform/> 
            <RotateTransform Angle="-90"/> 
            <TranslateTransform/> 
        </TransformGroup> 
    </TextBlock.RenderTransform> 
</TextBlock> 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.