12

我正在尝试在 WPF 应用程序中创建一个透明的 ListBox。我希望 ListBox 完全透明,因此背景图像在 ListBox 的“后面”可见。但是,我希望我的 ListBox 项目完全不透明,也就是说,它们位于背景图像的顶部。

有谁知道我怎么能做到这一点?

提前谢谢!

4

1 回答 1

25

当然,这很简单,只需将 ListBox 上的 Background 和 BorderBrush 属性设置为透明,然后为 ListBoxItems 设置背景:

<StackPanel Background="Red">
    <ListBox Background="Transparent" BorderBrush="Transparent">
        <ListBox.Resources>
            <Style TargetType="{x:Type ListBoxItem}">
                <Setter Property="Background" Value="White" />
                <Setter Property="Margin" Value="1" />
            </Style>
        </ListBox.Resources>
        <ListBoxItem Content="First Item"/>
        <ListBoxItem Content="Secton Item"/>
    </ListBox>
</StackPanel>

注意:我在 ListBoxItems 中添加了一个 Margin,只是为了说明 ListBoxItems 之间的间距将一直显示到周围的 StackPanel 的红色背景。

于 2009-11-01T20:53:22.973 回答