views:

30

answers:

2

I am using a ListBox with a DataTemplate to create the below map legend. I would like to get the ListBox to have a transparent background (where it is now white) and the ListItems to retain their existing white background. The two legends would then appear to float with a transparent gap between.

I have tried setting the ListBox background with a SolidBrush set to 0 opacity but that doesn't seem to work. I understand that items in the tree cannot have transparency that is less than items above in the tree. Is that my issue and how do I resolve?

Thanks

alt text

+1  A: 

Did you try setting the background color of the ListBox to "Transparent" (literally)?

Here is some code that worked for me:

<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>
RQDQ
Yes. Didn't work.
Douglas
Can you share some more of your XAML? I'm able to construct a ListBox that has transparency around each of its templated items...
RQDQ
Here is the xaml. I've tried both Null and Transparent.
Douglas
A: 

You can set the Background to {x:Null}.

Mario C