2008-09-30 48 views
0

如何设置列表框的背景颜色?我有一个包含文本块的列表框,但似乎没有任何实际的工作来设置这些控件的背景颜色,为什么这看起来很难?设置Silverlight列表框的背景颜色

在充分披露的利益,我问过类似的question较早

回答

2

您可以使用ListBox.ItemContainerStyle属性做到这一点。非常好的解释可以发现here。基于该示例,我们可以将ItemContainterStyle设置为具有透明背景色,然后将ListBox包装在边框中(ListBox不显示其背景色)。

<Border Background="Green"> 
<ListBox Background="Red"> 
    <ListBox.ItemContainerStyle> 
     <Style TargetType="ListBoxItem"> 
      <Setter Property="Background" Value="Transparent"/> 
     </Style> 
    </ListBox.ItemContainerStyle> 
    <TextBlock Text="Hello" /> 
    <TextBlock Text="Goodbye" /> 
    </ListBox> 
</Border> 

如果您只是想设置实际项目,您可以将背景设置为实际颜色,然后跳过边框。