2009-08-25 9 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を使用しただけで...

です。 using 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

RenderTransformの代わりにLayoutTransformを使用してください。これにより、レイアウトロジックがアイテムの変換された位置を考慮に入れるようになります。

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

ありがとう、完璧! –

関連する問題