DataGrid行的条件文本颜色? [英] Conditional text-color for the DataGrid rows?

查看:145
本文介绍了DataGrid行的条件文本颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个datagrid绑定到一个数据库表。我需要将一行的前色改为蓝色,这取决于其中一列的值。有没有办法我可以做到这一点?我尝试过IValueConverter,但我认为我一次只能使用一个单元格。

解决方案

 < DataGrid> 
< DataGrid.CellStyle>
< Style TargetType ={x:Type DataGridCell}>
< Style.Triggers>
< DataTrigger Binding ={Binding SomeProperty}Value =SomeValue>
< Setter Property =ForegroundValue =Blue/>
< / DataTrigger>
< /Style.Triggers>
< / Style>
< /DataGrid.CellStyle>
< / DataGrid>


I have a datagrid which is bound to a database table. I need to change the forecolor of a row to blue depending on there is a value in one of its columns. Is there a way I can do this? I tried IValueConverter, but I presume I can use this only for one cell at a time.

解决方案

<DataGrid>
    <DataGrid.CellStyle>
        <Style TargetType="{x:Type DataGridCell}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding SomeProperty}" Value="SomeValue" >
                    <Setter Property="Foreground" Value="Blue" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </DataGrid.CellStyle>
</DataGrid>

这篇关于DataGrid行的条件文本颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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