垂直旋转的文本块占据整个宽度,就像水平旋转一样
我将 TextBlock
控件包裹在边框中,这样我就可以看到占用空间的内容:
这是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:
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:
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
发生这种情况是因为像大多数 Web 基础应用程序一样,有一系列事件被触发/触发,我们习惯于在渲染事件中看到或处理发生的大部分事件。可以说,到那时页面已经提供了我不是 100% 确定,但我真的认为 LayoutTransform 发生在预渲染期间
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
我在运行时创建文本块并旋转它们时遇到了同样的问题。
我简单地通过设置来解决它,
看起来好像你没有设置它们,变换正在对居中的文本进行计算并添加宽度以将其放置在你想要的位置......
I had the same problem while creating textblocks on runtime and rotating them.
I solved it simply by setting
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...