Files to look at:
- BindingToColorConverter.cs (VB: BindingToColorConverter.vb)
- CellsHightlightHelper.cs (VB: CellsHightlightHelper.vb)
- HighlightedGridCell.cs (VB: HighlightedGridCell.vb)
- MainWindow.xaml (VB: MainWindow.xaml)
- MainWindow.xaml.cs (VB: MainWindow.xaml.vb)
- DataHelper.cs (VB: DataHelper.vb)
- ViewModel.cs (VB: ViewModel.vb)
To change a specific grid cell color, use the solution from the Styles and Templates Overview article.
In case of a simple scenario, when you need to highlight a cell based on its value or some other property that is available in the current row object, just specify a correct binding. For example:
<Style x:Key="customCellStyle" BasedOn="{StaticResource {dxgt:GridRowThemeKey ResourceKey=CellStyle}}" TargetType="dxg:CellContentPresenter">
<Setter Property="Background" Value="{Binding Path=RowData.Row.SomeFieldName, Converter={local:YourConverter}}"/>
</Style>
Optimized mode
<Style x:Key="customCellStyle" BasedOn="{StaticResource {dxgt:GridRowThemeKey ResourceKey=LightweightCellStyle}}" TargetType="dxg:LightweightCellEditor">
<Setter Property="Background" Value="{Binding Path=RowData.Row.SomeFieldName, Converter={local:YourConverter}}"/>
</Style>
However, if your cells should be colored based on complex logic, then a simple binding won't help you. In this case, it is better to create an attached property and bind to this property. Then, update this property when it is necessary.
For example, if a specific row color depends on other rows, handle data changes in your datasource and update your attached property based on these changes.
This example demonstrates the main idea of how to implement this functionality.
See also:
How to change background color for modified cells