2011-11-24 87 views
7

我有一个绑定到数据库表的数据网格。我需要将行的前景更改为蓝色,具体取决于其中一列的值。有什么办法可以做到这一点?我试过IValueConverter,但我认为我一次只能用于一个单元格。DataGrid行的条件文本颜色?

回答

19
<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> 
+0

我想改变行的前景作为一个整体... – sony

+0

您是否试过这段代码?我向你保证,这会改变整个行的前景色。除非你使用DataGridTemplateColumns或其他东西。 – kevev22

+0

@ kevev22即使这样它应该工作,除非个别模板overrdie TextBlock.Foreground :) – 2011-11-24 17:15:40