【问题标题】:How to rotate Text in WPF by keeping the Auto-Sizing function如何通过保持自动调整大小功能来旋转 WPF 中的文本
【发布时间】:2011-06-23 17:22:14
【问题描述】:

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

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

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

【问题讨论】:

    标签: wpf text rotation


    【解决方案1】:

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

    【讨论】:

    • 在 Blend 中,这有点“隐藏”——这意味着默认情况下您会看到 RenderTransform,并且必须展开 Transforms 面板才能看到 LayoutTransform。我从来没有注意到它在那里,但它确实隐藏在几乎显而易见的地方。
    • @Rachel UWP 可以使用 LayoutTransform 吗?
    【解决方案2】:

    就像 Rachel 说的使用 LayoutTransform

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

    【讨论】:

      【解决方案3】:
      <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> 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-06-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多