如何使DataGrid透明?

7

如何使DataGrid透明?
我尝试使用DataGrid本身的背景,但似乎不起作用。

更新:我只需要将背景和边框设置为透明,文本应该是可见的。


如果你把它变成透明的,你还需要它吗? :) - Shoban
背景="透明" - isxaker
7个回答

23

因此,我的解决方案是...同时使用Background="Transparent"和RowBackground="Transparent"


1
也可以使用 AlternatingRowBackground="Transparent"。 - Robert Graves

2
<DataGrid
      Background="Transparent" RowBackground="Transparent">
</DataGrid>

2

你尝试过将Opacity属性设置为0.0吗?

将值设为0.0会使元素完全透明。


1

试试这个:

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>

0

当你初始化datagrid时,请使用GridLinesVisibility标签并带上参数None

例如:

<DataGrid GridLinesVisibility="None"/>

0

这是一个未记录的功能,但如果您将可见性设置为隐藏,则与将元素设置为透明相同。


这并不是完全准确的:元素的可见性为“Collapsed”时,它们不参与输入事件(或命令),不影响布局的测量或排列过程,不在选项卡序列中,并且在命中测试中不会被报告。这是一个重要的考虑因素。 - Dan J
没错,说得有道理。我的陈述并不准确,但从用户的角度来看,隐藏它而不是将不透明度设置为0会是更好的解决方案,因为仅仅使其透明会产生意外的行为。这取决于OP实际想要实现什么。 - BenCr

0

我不确定您想要更改哪个背景,但是您可以通过覆盖DataGrid的ControlTemplate来设置任何背景。您最好的选择可能是从这里复制默认的DataGrid ControlTemplate,然后修改必要的背景以满足您的需求。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接