我有一個綁定到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