アイテムコントロールにバインドしている文字列のリストがあります。
文字列は、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; }
}
}