2009-08-25 59 views
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; } 

} 
} 

回答

5

使用LayoutTransform而不是RenderTransform。這將確保佈局邏輯考慮項目的轉換位置。

<Border BorderThickness="1" BorderBrush="Black" Width="200" Height="20" LayoutTransform="{StaticResource Rotate}"> 
+0

非常感謝,完美! – 2009-08-25 16:27:02