2010-08-11 119 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:空}。