【发布时间】:2015-11-04 15:05:47
【问题描述】:
我有一个 WPF DataGrid,它绑定到一个可观察的 RowObjects 集合,并带有一堆可绑定的属性。为了填写表格中的数据,我添加了绑定到 RowObjects 属性的 DataGridTextColumns。例如:
<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,但这似乎不能直接工作。有什么想法吗?
【问题讨论】:
标签: c# wpf data-binding datagrid