我试图创建一个WPF应用程序透明的ListBox。我想列表框是完全透明的,这样一个背景图像是可见的幕后黑手列表框。不过,我想我的列表框项目是完全以不透明的,也就是说,他们躺在背景图像的顶部。
I'm trying to create a transparent ListBox in a WPF application. I want the ListBox to be completely transparent, thus a background image is visible "behind" the ListBox. However, I want my ListBox items to be totaly opaque, that is to say, they lay on top of the background image.
难道有谁知道我能做到这一点?
Do anyone know how I can accomplish this?
感谢名单提前!
当然,它的简单,只要在列表框透明设置背景和BorderBrush属性,然后设置背景的ListBoxItems:
Sure, it's as simple as setting the Background and BorderBrush properties on the ListBox to Transparent and then setting a Background for the 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只是demostrate的ListBoxItems之间的间距将通过展示向周围的StackPanel的红色背景一路
NOTE: I added a Margin to the ListBoxItems just to demostrate the spacing between the ListBoxItems will show all the way through to the surrounding StackPanel's red background.