我正在尝试创建一个透明的WPF应用程序中的ListBox。 我希望ListBox完全透明,因此可以看到背景图像“在”ListBox后面。 但是,我希望我的ListBox项目完全不透明,也就是说,它们位于背景图像上方。
有人知道我如何实现这个吗?
提前感谢!
我正在尝试创建一个透明的WPF应用程序中的ListBox。 我希望ListBox完全透明,因此可以看到背景图像“在”ListBox后面。 但是,我希望我的ListBox项目完全不透明,也就是说,它们位于背景图像上方。
有人知道我如何实现这个吗?
提前感谢!
当然,只需要在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>
注意: 我添加了一个Margin到ListBoxItems仅仅是为了演示ListBoxItems之间的间距会一直显示到周围StackPanel的红色背景中。