如何通过保持自动大小调整功能来旋转WPF中的文本

时间:2022-02-14 08:12:45

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?

我想要一个垂直的文本。我只是在WPF中使用一个简单的网格来自动调整区域大小。但是当使用RotateTransform时,所有的计算都是错误的。你知道怎么解决这个问题吗?

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

如何通过保持自动大小调整功能来旋转WPF中的文本 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.

在这幅图中,你可以看出我的意思。如果我现在想要自动调整中间部分的大小,我不能使用“Width”或“Height”属性,因为这两个属性都会导致错误的大小。宽度=120px将增加horicontal(原始)宽度,使整行为120pixel。高度=120px将使文本高度为120px。

3 个解决方案

#1


65  

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

使用LayoutTransform而不是RenderTransform。它将在布局传递期间应用,而不是在呈现期间。

#2


22  

Like Rachel said use LayoutTransform

就像瑞秋说的使用LayoutTransform

<TextBlock Text="Goodday" >
   <TextBlock.LayoutTransform>
     <RotateTransform Angle="90" />
   </TextBlock.LayoutTransform>  
</TextBlock>

#3


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> 

#1


65  

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

使用LayoutTransform而不是RenderTransform。它将在布局传递期间应用,而不是在呈现期间。

#2


22  

Like Rachel said use LayoutTransform

就像瑞秋说的使用LayoutTransform

<TextBlock Text="Goodday" >
   <TextBlock.LayoutTransform>
     <RotateTransform Angle="90" />
   </TextBlock.LayoutTransform>  
</TextBlock>

#3


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>