设置Silverlight列表框的背景颜色

时间:2008-09-30 21:28:42

标签: silverlight

如何设置列表框的背景颜色?我有一个带有文本块的列表框,似乎无论如何实际上都没有设置这些控件的背景颜色,为什么这看起来很难?

为了完全披露,我早先问过类似的question

1 个答案:

答案 0 :(得分:2)

您可以使用ListBox.ItemContainerStyle属性执行此操作。可以找到对here的非常好的解释。基于该示例,我们可以将ItemContainterStyle设置为具有透明背景颜色,然后将ListBox包装在Border中(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>

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

相关问题