如何通过保留自动调整大小功能在 WPF 中旋转文本

发布于 2024-11-17 00:43:53 字数 549 浏览 5 评论 0原文

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

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

WPF 旋转文本 在这张图片中你明白我的意思了。如果我现在想自动调整中间部分的大小,我不能使用“宽度”或“高度”属性,因为两者都会产生错误的大小调整结果。宽度 =120px 将增加水平(原始)宽度,并使整行为 120 像素。 Height=120px 将使文本高度为 120 像素。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

年少掌心 2024-11-24 00:43:53

使用 LayoutTransform 而不是 RenderTransform。它在布局过程中应用,而不是在渲染过程中应用。

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

椒妓 2024-11-24 00:43:53

就像 Rachel 说的,使用 LayoutTransform

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

Like Rachel said use LayoutTransform

<TextBlock Text="Goodday" >
   <TextBlock.LayoutTransform>
     <RotateTransform Angle="90" />
   </TextBlock.LayoutTransform>  
</TextBlock>
红衣飘飘貌似仙 2024-11-24 00:43:53
<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> 
<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> 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文