我已經做了一些研究,並且找到了爲每個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高度上設置替代背景?
我唯一能做的就是不用創建新的控件,而是巧妙地將背景看做空的交替項目,但只有在事先知道項目高度的情況下才能做到這一點匹配滾動位置很可能是一場噩夢。 –