2011-03-18 72 views
6

如何讓DataGrid透明?
我想使用DataGrid本身的背景,但這似乎並不奏效。如何使DataGrid透明?

UPD我只需要背景和邊框透明,而不是一切!文字應該是可見的。

+0

如果您使其透明爲什麼你需要它? :) – Shoban 2011-03-18 15:25:47

+0

background =「transparent」 – isxaker 2011-03-18 15:28:25

回答

14

所以,我的解決方案......同時使用背景= 「透明」 和RowBackground = 「透明」

+1

另外AlternatingRowBackground =「透明」 – 2015-04-22 18:35:52

1

您是否嘗試過將Opacity屬性設置爲0.0?

值爲0.0使元素 完全透明

+0

不完全...請參閱UPD – user626528 2011-03-19 14:47:08

0

這是一個undocumentd功能,但如果你的visability設置爲隱藏它是一樣的元素設置爲透明。

+0

這不是[完全準確:](http://msdn.microsoft.com/en-us/library/system.windows.uielement.visibility.aspx )*「可視性不可見的元素不參與輸入事件(或命令),不影響佈局的度量或排列傳遞,不在選項卡序列中,並且不會在命中測試中報告。」*重要的考慮。 – 2011-03-18 16:35:33

+0

沒錯。我的陳述並不準確,但從用戶的角度來看,隱藏它而不是將不透明度設置爲0會是一個更好的解決方案,因爲只是使其可轉換會產生意想不到的行爲。取決於OP實際嘗試實現的內容。 – BenCr 2011-03-18 17:01:13

0

我不確定您要更改哪個背景,但可以通過覆蓋DataGrid的ControlTemplate來設置任何背景。您最好的選擇是從這裏複製默認的DataGrid ControlTemplate,然後修改必要的背景以符合您的需求。

1
<DataGrid 
     Background="Transparent" RowBackground="Transparent"> 
</DataGrid> 
0

試試這個:

Background="Transparent" RowBackground="Transparent" 

<DataGrid.ColumnHeaderStyle> 
    <Style TargetType="{x:Type DataGridColumnHeader}"> 
     <Setter Property="Background" Value="Transparent" /> 
     <Setter Property="FontWeight" Value="Bold" /> 
    </Style> 
</DataGrid.ColumnHeaderStyle> 

<DataGrid.RowHeaderStyle> 
    <Style TargetType="{x:Type DataGridRowHeader}"> 
     <Setter Property="Background" Value="Transparent" /> 
    </Style> 
</DataGrid.RowHeaderStyle>