wpf透明度

时间:2010-08-11 18:29:13

标签: wpf transparency

我正在使用带有DataTemplate的ListBox来创建下面的地图图例。我想让ListBox具有透明背景(现在它是白色的)和ListItems以保留它们现有的白色背景。然后两个传说似乎浮动,两者之间有透明的间隙。

我尝试设置ListBox背景,将SolidBrush设置为0不透明但这似乎不起作用。我知道树中的项目的透明度不能低于树中上面的项目。这是我的问题,我该如何解决?

由于

alt text http://www.freeimagehosting.net/uploads/659cd194e7.png

2 个答案:

答案 0 :(得分:2)

您可以将背景设置为{x:Null}。

答案 1 :(得分:1)

您是否尝试将ListBox的背景颜色设置为“透明”(字面意思)?

以下是一些对我有用的代码:

<Window x:Class="WpfApplication3.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" Background="Blue">
    <Grid>

        <ListBox x:Name="ListBox1" Margin="12,25,114,97" Background="#00E51A1A">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid Margin="4" Height="20" Width="100" Background="Yellow" />
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

    </Grid>
</Window>