根据单元格的内容设置DataGridRow的背景

Phi*_*Gan 6 wpf xaml wpftoolkit wpfdatagrid

有没有办法,使用XAML,根据其中一个单元格的内容动态设置行的背景?

谢谢,

菲尔

Pav*_*kov 18

您可以为行定义样式并使用DataTrigger更改颜色.像这样的东西:

<DataGrid>
    <DataGrid.RowStyle>
        <Style TargetType="DataGridRow">
            <Style.Triggers>
                <DataTrigger Binding="{Binding BooleanPropertyOnObjectBoundToRow}" Value="True">
                   <Setter Property="Background" Value="Red"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </DataGrid.RowStyle>
</DataGrid>
Run Code Online (Sandbox Code Playgroud)

BooleanPropertyOnObjectBoundToRow是一个单元格绑定到的数据对象的布尔属性.

  • @Phil:您还可以为Binding的Value-proeprty指定自己的枚举值.为此,您必须声明枚举的名称空间,并在value属性中将其设置为Value ="{x:Static yourNamespace:YourEnum.YourValue}" (6认同)