我有一个绑定到RowObjects的可观察集合的WPF DataGrid,它具有一组可绑定属性。为了填充表格中的数据,我添加了DataGridTextColumns,它们绑定到RowObjects的属性。例如:WPF绑定到CellStyle的DataGrid上下文
<DataGrid ItemsSource={Binding RowCollection}>
<DataGrid.Columns>
<DataGridTextColumn Header="Col1" Binding={Binding Property1Name, Mode=OneTime} IsReadOnly="True" />
<DataGridTextColumn Header="Col2" Binding={Binding Property2Name, Mode=OneTime} IsReadOnly="True" />
<DataGridTextColumn Header="Col3" Binding={Binding Property3Name, Mode=OneTime} IsReadOnly="True" />
</DataGrid.Columns>
</DataGrid>
让我们假设Property3是一个整数。我希望Column3中的单元格在负值时突出显示为红色,零点时显示为黄色,正值时显示为绿色。我的第一个想法是将System.Windows.Media.Color绑定到DataGridTextColumn的CellStyle,但这似乎并不直接工作。有任何想法吗?
我已经提出了几乎相同的解决方案,晚了17秒...你赢了这次 – Jose