首页 文章

如何更改所选数据网格行的蓝色

提问于
浏览
4

好吧,我已经看到这个代码来做到这一点:

<DataGrid.RowStyle>
    <Style TargetType="DataGridRow">

        <Style.Triggers>
            <Trigger Property="IsSelected" Value="True">
                <Setter Property="Background" Value="Black"/>
                <Setter Property="Foreground" Value="Green">
                </Setter>
            </Trigger>
        </Style.Triggers>

        <Setter Property="Background">                        
            <Setter.Value>
                <MultiBinding Converter="{StaticResource ucComponentesColorFilaMultiValueConverter}">
                    <Binding ElementName="dgdComponentes" Path="ItemsSource" />
                    <Binding ElementName="dgdComponentes" Path="SelectedItems" />
                    <Binding ElementName="CurrentItem" />
                </MultiBinding>
            </Setter.Value>
        </Setter>
    </Style>
</DataGrid.RowStyle>

真的是代码是样式触发器,setter属性是针对其他情况的,但是我添加的代码可以影响结果 .

我想更改选定的行背景,默认情况下是蓝色,我想根据某些条件使用其他颜色 . 例如,如果添加了一个寄存器,那么如果我选择该行它将为绿色,如果未选中该行,则它将为浅绿色 .

我可以根据需要更改行的颜色,但是当我选择它时,总是蓝色 .

谢谢 .

2 回答

  • 0

    你可以试试这样的事......

    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
           <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
    
  • 14

    为此,您需要以编程方式指定行的颜色

    <Setter Property="Background" Value="{Binding Path=BgColor}"/>
    

    BgColor 属性添加到绑定到网格的对象 . 在您的条件设置 BgColor (即如果对象是注册,那么BgColor是"Green")

相关问题