wpf工具包datagrid中的条件格式

问题描述:

嘿,我想根据模型中的布尔值更改行前景色,最好的方法是什么?

hey i wanna change row foreground color according to a boolean in the model, whats the best way of doing it?

按以下方式定义样式(IsBlah是布尔型属性):

Define the style as following (IsBlah is a boolian property):

    <Style x:Key="MyRowStyle" TargetType="{x:Type dg:DataGridRow}">
        <Setter Property="Background" Value="White"/>
        <Setter Property="Foreground" Value="DarkBlue"/>            
        <Style.Triggers>
            <DataTrigger Binding="{Binding IsBlah}" Value="False" >
                <Setter Property="Background" Value="DarkGray" />
                <Setter Property="Foreground" Value="White" />
            </DataTrigger>
        </Style.Triggers>
    </Style>

您的DataGrid应该具有自定义的RowStyle。 (RowStyle = {StaticResource MyRowStyle})

Your DataGrid should have a custom RowStyle. (RowStyle="{StaticResource MyRowStyle})