我怎样才能让列表框透明的,但列表框项目不透明WPF? [英] How can I make listbox transparent, but listbox items opaque in WPF?

查看:188
本文介绍了我怎样才能让列表框透明的,但列表框项目不透明WPF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个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.

这篇关于我怎样才能让列表框透明的,但列表框项目不透明WPF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆