2011-03-18 73 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>