wpf在textblock上旋转并转换转换问题

And*_*rke 1 wpf transformation textblock itemscontrol

我有一个字符串列表,我绑定到一个项目控件.

字符串显示在我在itemscontrol模板中声明的文本块中.我已经旋转了文本块270以使文本在它的一边 - 我还将文本块的宽度向下翻译,使它们位于页面的顶部.

我的问题是它们现在距离太远,因为它保持原始宽度而不是变换宽度.我能理解它为什么这样做,但我需要把它们叠在一起,没有间隙.

有人能指出我正确的方向吗?

<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="354" Width="632"
        DataContext="{Binding RelativeSource={RelativeSource Self}}" >
<Window.Resources>
    <TransformGroup x:Key="Rotate">
        <RotateTransform Angle="270" />
        <TranslateTransform Y="200" />
    </TransformGroup>
</Window.Resources>
<StackPanel Orientation="Vertical">
    <ItemsControl ItemsSource="{Binding MyStrings}" HorizontalAlignment="Left"  >
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal"/>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Border BorderThickness="1" BorderBrush="Black" Width="200" Height="20" RenderTransform="{StaticResource Rotate}" >
                    <TextBlock Text="{Binding }"  >
                    </TextBlock>
                </Border>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</StackPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)

并且背后的代码只是......

使用System.Collections.Generic; 使用System.Windows;

namespace WpfApplication1
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
    public Window1()
    {
        MyStrings = new List<string> {"monkey", "turtle", "rabbit"};
        InitializeComponent();
    }

    public List<string> MyStrings { get; set; }

}
}
Run Code Online (Sandbox Code Playgroud)

Ken*_*art 5

LayoutTransform而不是RenderTransform.这将确保布局逻辑考虑到项目的转换位置.

<Border BorderThickness="1" BorderBrush="Black" Width="200" Height="20" LayoutTransform="{StaticResource Rotate}">
Run Code Online (Sandbox Code Playgroud)