WPF旋转文本

use*_*414 5 wpf rotation

我试着做这样的事情:

在此输入图像描述

我有一个带有我自己的对象的List,在这个List中我有绘制它的所有信息,我有一个Listbox,每个图都是我在画布的位置绘制的Listbox项.

我的问题是当我想绘制名称时,因为我必须旋转名称并在名称的矩形内绘制它,但是当我旋转名称时我不知道如何在de rectangle内绘制它.

我将这个数据模板用于我的列表框ItemTemplate,我根据我是否要绘制图像或名称来设置可见性.

<DataTemplate x:Key="templateList">
    <Canvas >
        <WrapPanel 
                  Visibility="{Binding IsStone, Converter={StaticResource converterCheckIsVisibleName}}"
                  Width="{Binding ObjectName.Width}"
                  Height="{Binding ObjectName.Height}">

                <TextBlock Text="{Binding ObjectName.Name}" >
                    <TextBlock.RenderTransform>
                        <RotateTransform Angle="{Binding ObjectName.Rotate}" />
                    </TextBlock.RenderTransform>
                </TextBlock>
            </WrapPanel>


           <Border BorderThickness="1"  BorderBrush="Black" 
                        Visibility="{Binding IsStone, Converter={StaticResource converterCheckIsVisibleStone}}">
                    <Image Source="{Binding ObjectIMG.PathImagen}" 
                           Height="{Binding ObjectIMG.Height}"
                           Width="{Binding ObjectIMG.Width}"
                           Stretch="Fill" />
                </Border>

            </Canvas>                                        
        </DataTemplate>
Run Code Online (Sandbox Code Playgroud)

She*_*dan 8

我不是100%确定您的问题是什么,但似乎您只想旋转一些文本并将其放入矩形.本Rectangle类并不需要一个内容元素,所以你不能使用,但你可以用一个简单的Border元素.

另外需要注意的是,您应该使用在布局传递之前LayoutTransform发生的事件,而不是之后应用的事件.有关此内容的详细信息,请参阅MSDN上的FrameworkElement.LayoutTransform属性页.尝试这样的事情:RenderTransform

<Border BorderBrush="Black" BorderThickness="5">
    <TextBlock Text="{Binding ObjectName.Name}" >
        <TextBlock.LayoutTransform>
            <RotateTransform Angle="{Binding ObjectName.Rotate}" />
        </TextBlock.LayoutTransform>
    </TextBlock>
</Border>
Run Code Online (Sandbox Code Playgroud)