1
我有我绑定到项目控件的字符串列表。wpf旋转和翻译文本块上的变换问题
字符串显示在我在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>
和后面的代码只是...
使用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; }
}
}
非常感谢,完美! – 2009-08-25 16:27:02