垂直旋转的Textblock占据整个宽度,就好像它是水平的一样

Onl*_*ere 1 c# wpf xaml textblock text-rotation

我已将TextBlock控件包裹在边框中,这样我就能看到占用空间的东西:

在此输入图像描述

这是XAML:

<Border BorderBrush="Cyan" BorderThickness="3">
    <TextBlock Style="{StaticResource subtitle}" Text="{Binding Title}" >
        <TextBlock.RenderTransform>
            <RotateTransform Angle="90" />
        </TextBlock.RenderTransform>
    </TextBlock>
</Border>
Run Code Online (Sandbox Code Playgroud)

问题是这占用的空间比我需要的多得多,如果我设置一个静态宽度,我得到这个:

在此输入图像描述

有什么建议?

Met*_*Man 6

<Setter Property="LayoutTransform"> 
    <Setter.Value> 
        <RotateTransform Angle="90" /> 
    </Setter.Value> 
</Setter> 
Run Code Online (Sandbox Code Playgroud)

这种情况发生了,因为在大多数Web Base应用程序中都有一系列事件会触发/触发我们用于查看或处理的大部分事件发生在渲染事件中......到那时页面已经提供了可以这么说我不是100%肯定,但我真的认为LayoutTransform在预渲染期间发生

  • @SergioTapia"LayoutTransform"工作的原因是因为它在TextBlock呈现之前被应用.渲染TextBlock后应用`RenderTransforms`,并在UI中阻止了它的空间.DJ,如果你想在你的答案中添加这样的解释,我会投票:) (2认同)