垂直旋转的文本块占据整个宽度,就像水平旋转一样

发布于 2024-12-22 07:21:36 字数 616 浏览 3 评论 0原文

我将 TextBlock 控件包裹在边框中,这样我就可以看到占用空间的内容:

enter image这里的描述

这是XAML:

<Border BorderBrush="Cyan" BorderThickness="3">
    <TextBlock Style="{StaticResource subtitle}" Text="{Binding Title}" >
        <TextBlock.RenderTransform>
            <RotateTransform Angle="90" />
        </TextBlock.RenderTransform>
    </TextBlock>
</Border>

问题是它占用的空间比我需要的多得多,如果我为其设置静态宽度,我会得到以下结果:

在此处输入图像描述

有什么建议吗?

I've wrapped the TextBlock control in a border so I could see what's taking up space:

enter image description here

Here is the XAML:

<Border BorderBrush="Cyan" BorderThickness="3">
    <TextBlock Style="{StaticResource subtitle}" Text="{Binding Title}" >
        <TextBlock.RenderTransform>
            <RotateTransform Angle="90" />
        </TextBlock.RenderTransform>
    </TextBlock>
</Border>

The problem is that this is taking up much more room than I need it to, and if I set a static width to it, I get this:

enter image description here

Any suggestions?

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

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

发布评论

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

评论(2

北渚 2024-12-29 07:21:36
<Setter Property="LayoutTransform"> 
    <Setter.Value> 
        <RotateTransform Angle="90" /> 
    </Setter.Value> 
</Setter> 

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

<Setter Property="LayoutTransform"> 
    <Setter.Value> 
        <RotateTransform Angle="90" /> 
    </Setter.Value> 
</Setter> 

This happed because like in most Web Base Applications there is a series of events that get trigger / fired most of what we are use to seeing or dealing with happens in the Rendering Event.. by then the page has already been served up so to speak I am not 100% sure but I am really thinking that the LayoutTransform happens during pre-Rendering

梦旅人picnic 2024-12-29 07:21:36

我在运行时创建文本块并旋转它们时遇到了同样的问题。
我简单地通过设置来解决它,

tb.Margin = .......
tb.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left;
tb.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Top;
RotateTransform rt = new RotateTransform();
rt.Angle = -40;
tb.RenderTransform = rt;

看起来好像你没有设置它们,变换正在对居中的文本进行计算并添加宽度以将其放置在你想要的位置......

I had the same problem while creating textblocks on runtime and rotating them.
I solved it simply by setting

tb.Margin = .......
tb.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left;
tb.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Top;
RotateTransform rt = new RotateTransform();
rt.Angle = -40;
tb.RenderTransform = rt;

it seems as if you don't set them, the transform is doing its calcs on the centered text and adding width to position it where you wanted...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文