これらの TextBlocks を手動で設定したとき、0(ゼロ) に設定された最初のものを除いて、左マージンを -50 に変更することで適切に配置することができました。
バインディングを通じて TextBlocks を取得するようになったので、スタイルを適用すると、すべての TextBlocks に適用されます。
<Style x:Key="RotatedText" TargetType="TextBlock">
<Setter Property="LayoutTransform">
<Setter.Value>
<RotateTransform Angle="-45" />
</Setter.Value>
</Setter>
<Setter Property="Width" Value="130"/>
<Setter Property="Margin" Value="-50,0,0,0"/>
</Style>
これが起こります:
私が疑問に思っているのは、すべての TextBlock で機能するスタイルを作成する方法、または最初の TextBlock と残りの部分に別のスタイルを定義する方法です。
<ListBox x:Name="lstModules" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.Modules}" BorderBrush="{x:Null}" Background="{x:Null}" BorderThickness="0">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" CanVerticallyScroll="False" CanHorizontallyScroll="False"></StackPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Style="{StaticResource ListViewItemRotatedText}" Text="{Binding ModuleName}"></TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>