WPF:如何以不同的方向书写文本? [英] WPF: how to write text in a different direction?

查看:27
本文介绍了WPF:如何以不同的方向书写文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要按照为下图指定的方向书写文本.事实上,我在这里看到了一些使用文本块并使用RenderTransform"旋转控件角度的示例,但这并不是我真正需要的.我尝试使用图像来完成它,但它不太适合......所以我真的不知道如何解决它.如果您查看旁边的图像,您可以看到文本是从下到上书写的,文本下方的一行位于屏幕右侧.这是我需要开发的屏幕:

I need to write text in the orientation specified for the image below. The fact is that I saw some examples around here by using a textblock and rotating the angle of the control using "RenderTransform", but this is not what I really need. I tried to do it using an image but it doesn't fit very well... so I really don't know how to solve it. If you look at the image beside you can see that the text is written from bottom to top and the line below the text is in the right of the screen. This is the screen that I need to develop:

我尝试旋转文本块,但它对我有用的唯一方法是包装文本,但这只是我找到的最接近"的解决方案.另外,如您所见,我需要为文本块设置边框.

I tried by rotating the textblock, but the only way that it works for me was wrapping the text, but this is just the "closest" solution that I found. Also, as you can see, I need to set a border for the textblock.

无论如何,我希望你能帮助我,因为任何例子都适合我的问题.

Anyway, I hope you can help me because any example around fits with my problem.

推荐答案

为了将文本旋转 90 度,我相信您需要使用 LayoutTransform 而不是 渲染变换:

In order to rotate your text at 90 degrees, I believe that you will need to use the LayoutTransform instead of the RenderTransform:

<TextBlock Text="FootRoller" HorizontalAlignment="Center" VerticalAlignment="Center">
    <TextBlock.LayoutTransform>
        <RotateTransform Angle="-90"/>
    </TextBlock.LayoutTransform>
</TextBlock>

区别在于何时将应用转换.使用 LayoutTransform,文本将在布局传递之前 旋转,这对您的情况很重要.我想使用 RenderTransform 会旋转你的 TextBlock,但正如它在布局传递之后 所做的那样,它不会显示所有内容... 这是因为它在旋转之前测量尺寸.

The difference is when the transform will be applied. Using the LayoutTransform, the text will be rotated before the layout pass and this will be important in your case. I imagine that using the RenderTransform will rotate your TextBlock, but as it does that after the layout pass, it would not show it all... this is because it was measured for size before it was rotated.

您可以从 转换概述页面.从链接页面:

You can find out full details from the Transforms Overview page on MSDN. From the linked page:

LayoutTransform – 在布局传递之前应用的转换.应用变换后,布局系统会处理变换后的元素大小和位置.

LayoutTransform – A transform that is applied before the layout pass. After the transform is applied, the layout system processes the transformed size and position of the element.

RenderTransform – 修改元素外观但在布局传递完成后应用的变换.通过使用 RenderTransform 属性而不是 LayoutTransform 属性,您可以获得性能优势.

RenderTransform – A transform that modifies the appearance of the element but is applied after the layout pass is complete. By using the RenderTransform property instead of the LayoutTransform property, you can obtain performance benefits.

这篇关于WPF:如何以不同的方向书写文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆