简体   繁体   English

无论颜色如何,如何更改整个行的不透明度?

[英]How do I change opacity of entire row regardless of color?

I have a certain data-grid consisted of TextColumns and each of the cells differ in color. 我有一个由TextColumns组成的特定数据网格,每个单元格的颜色都不同。 I am basing my color on certain data and because of this I have set the cell's background color appropriately. 我将颜色设为某些数据的基础,因此,我已经适当设置了单元格的背景色。 The issue that came from this is that now when I select a row, there is no way to see if it is selected. 由此产生的问题是,现在选择行时,无法查看是否已选择行。 I dont want to dim each cell's color when I select the row, because I have a lot of columns. 选择行时,我不想使每个单元格的颜色变暗,因为我有很多列。 I just want to adjust the opacity of he selected row and not thing about the colors in individual cells. 我只想调整他选择的行的不透明度,而不是调整单个单元格中的颜色。 This is what I have tried: 这是我尝试过的:

<DataGrid.Resources>
    <Style TargetType="DataGridRow">
        <Style.Triggers>
            <Trigger Property="IsSelected" Value="True">
                <Setter Property="Background">
                    <SolidColorBrush Opacity="0.3"/>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>
</DataGrid.Resources>

But I get the error: Unexpected record in Baml stream. Trying to add to Setter which is not a collection or has a TypeConverter. 但是我得到了错误: Unexpected record in Baml stream. Trying to add to Setter which is not a collection or has a TypeConverter. Unexpected record in Baml stream. Trying to add to Setter which is not a collection or has a TypeConverter. Is there a way to acheive my expected result? 有没有办法达到我的预期结果?

You should set the Value (note the <Setter.Value> element) property to a SolidColorBrush : 您应该将Value (请注意<Setter.Value>元素)属性设置为SolidColorBrush

<Trigger Property="IsSelected" Value="True">
    <Setter Property="Background">
        <Setter.Value>
            <SolidColorBrush Opacity="0.3"/>
        </Setter.Value>
    </Setter>
</Trigger>

You may also want to change the TargetType to DataGridCell for the background to be applied to the selected cells. 您可能还需要将TargetType更改为DataGridCell以将背景应用于选定的单元格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM