根据单元格的内容设置DataGridRow的背景 [英] Set the Background of a DataGridRow based on the content of a cell

查看:37
本文介绍了根据单元格的内容设置DataGridRow的背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there a way, using XAML, to dynamically set the background of a row based on the content of one of it's cells?

谢谢,

菲尔

推荐答案

您可以为行定义样式并使用以下方法更改颜色DataTrigger。像这样:

You can define a style for a row and change the color using DataTrigger. Something like this:

<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>

此处 BooleanPropertyOnObjectBoundToRow 是您的布尔属性单元格绑定的数据对象之一。

Here BooleanPropertyOnObjectBoundToRow is a boolean property on your data object one the cells is bound to.

这篇关于根据单元格的内容设置DataGridRow的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆