How can I style WPF DataGrid to change the color of selected row when DataGrid lost its focus?
相关问题
- VNC control for WPF application
- WPF Binding from System.Windows.SystemParameters.P
- XAML: Applying styles to nested controls
- How can I add a horizontal line (“goal line”) for
- How to properly change a resource dictionary
None of these answers gave me quite what I was looking for. The top rated by Steve Streeting changed other sections of the datagrid that I didn't want to change, and other answers weren't providing the inactive color change, but were properly targeting the row only. So here's a mixture of their answers that changes the inactive color, only on the rows and not in other places on the grid.
Complete solution that works for 4.0. Note that this on the CellStyle.
For .Net Framework 4.0 (or if you don't want to use the InactiveSelection... brush keys): Create a DataGridRow style/control template, and add these triggers:
Find an answer by myself.
Add to DataGrid's resources the brush, which can change its 'Color' property from code behind, and reference HighlightBrushKey to it:
Then add DataGrids event handlers to manually change the color:
You should define section "DataGrid.CellStyle" inside your DataGrid like this:
I added this to my ResourceDictionary so that it applies to all data grids in my program.