2010-08-11 154 views
0

我正在使用带有DataTemplate的ListBox来创建下面的地图图例。我想让ListBox有一个透明的背景(它现在是白色的)和ListItems来保留他们现有的白色背景。这两个传说似乎会随着两者之间的透明差距而浮动。wpf透明度

我已经尝试设置列表框背景与SolidBrush设置为0不透明,但似乎并不工作。我知道树中的项目不能具有比树中的项目更少的透明度。这是我的问题,我该如何解决?

感谢

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

+0

哦 - 并且ListBox中的项目也可以具有透明背景。 – RQDQ 2010-08-11 18:38:58

回答

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> 
+0

是的。没有工作。 – Douglas 2010-08-11 18:39:42

+0

你能分享一些你的XAML吗?我能够构建一个ListBox,每个模板项目都有透明度... – RQDQ 2010-08-11 18:40:22

+0

这里是xaml。我试过Null和Transparent。 – Douglas 2010-10-01 18:10:48

2

您可以将背景设置为{X:空}。