1

私はいくつかの調査を行い、それぞれに別の背景色を設定する方法を見つけましたListBoxItemが、リストボックスが空であってもその背景を継続したい.

<Style x:Key="ListBoxStyle" TargetType="ListBox">
    <Setter Property="Width" Value="288"></Setter>
    <Setter Property="BorderBrush" Value="#D2D2D2"></Setter>
    <Setter Property="BorderThickness" Value="1"></Setter>
    <Setter Property="Margin" Value="1,0,1,0"></Setter>
    <Setter Property="AlternationCount" Value="2"></Setter>
    <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
</Style>

<Style x:Key="ListBoxItemStyle" TargetType="ListBoxItem">
    <Setter Property="Height" Value="27"></Setter>
    <Setter Property="FontWeight" Value="Medium"/>
    <Setter Property="FontSize" Value="12"/>
    <Setter Property="Foreground" Value="#333333"/>
    <Style.Triggers>
        <Trigger Property="ItemsControl.AlternationIndex" Value="0">
            <Setter Property="Background" Value="White"></Setter>
        </Trigger>
        <Trigger Property="ItemsControl.AlternationIndex" Value="1">
            <Setter Property="Background" Value="#19000000"></Setter>
        </Trigger>
    </Style.Triggers>
</Style>

ListBox の高さ全体に別の背景を設定することは可能ですか?

4

3 に答える 3

1

私の知る限り、それBackgroundを可能にするのはアイテムなので、いや、ありえないと思います。この効果を生み出すことができると想像できる唯一の方法は、空のアイテムを に追加することListBoxです。ただし、これらの空のアイテムは引き続き選択可能であり、ユーザーを混乱させる可能性があるため、そうしないことを強くお勧めします.

于 2013-10-07T08:45:50.473 に答える