1

これらの 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>
4

2 に答える 2

1

ListBox左に 50 のマージンを与えることで、全体を移動することができTextBlockますListBox

于 2013-06-05T15:57:27.250 に答える
0

IValueConverter を使用してアイテムを分析し、それがリストの最初のアイテムであるかどうかを確認しました。

<Style.Triggers>
    <DataTrigger Binding="{Binding ModuleName, Converter={StaticResource firstItemConvertion}}" Value="true">
        <Setter Property="Margin" Value="-60,0,0,0" />
    </DataTrigger>
</Style.Triggers>


public class FirstItemConverter : IValueConverter
{
    public object Convert(object obj, Type type, object parameter, CultureInfo culture)
    {
        return (int.Parse((string)parameter)) < ModuleRepository.GetModuleIndexByModuleName(((string)obj));
    }

    public object ConvertBack(object obj, Type type, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}
于 2013-06-06T04:05:50.937 に答える