-
Notifications
You must be signed in to change notification settings - Fork 23
Description
Is your feature request related to a problem? Please describe.
Currently, there's no built-in way to style the current row in a DataGrid using pseudoclasses. Developers need the selected item to be visually distinct beyond the default selection styling, but have to resort to custom behaviors, attached properties, or extending DataGridRow with reflection - all of which are complex workarounds for what should be a simple styling task.
The TreeDataGrid control already provides this functionality with the :current pseudoclass, but DataGrid lacks this feature, creating an inconsistency in the API.
Describe the solution you'd like
Add support for the :current pseudoclass on DataGridRow that is automatically set when the row's DataContext matches the parent DataGrid.SelectedItem.
This would enable pure XAML styling:
<Window.Styles>
<Style Selector="DataGridRow:current">
</Style>
</Window.Styles>
Implementation would be similar to TreeDataGrid:
- In DataGridRow: Update the :current pseudoclass state based on selection
- In DataGrid: Notify affected rows when SelectedItem changes
This would be a minimal change (~20-30 lines) that is backward compatible and non-breaking.
Describe alternatives you've considered
Current workarounds include:
- Custom behaviors with attached properties - adds complexity and code-behind
- Extending DataGridRow and using reflection to access internal properties - fragile and maintenance-heavy
- Manual styling in code-behind - violates MVVM pattern
- Using Styles with data triggers - limited and doesn't work for all scenarios
All alternatives are significantly more complex than the proposed pseudoclass support.
Additional context
Given that DataGrid is now in maintenance mode with no major feature enhancements planned, this small quality-of-life improvement seems like a worthwhile exception because:
- Low-risk: minimal, non-breaking change to mature codebase
- High value: immediate benefit to developers
- Feature parity: brings DataGrid in line with TreeDataGrid
- No ongoing maintenance burden
TreeDataGrid successfully implements this pattern, providing a proven reference implementation.
I'm willing to submit a PR with the implementation if the team is open to this enhancement.