Skip to content

Add :current PseudoClass to DataGridRow for Selected Item Styling #194

@DPalmaEng

Description

@DPalmaEng

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:

  1. In DataGridRow: Update the :current pseudoclass state based on selection
  2. 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:

  1. Custom behaviors with attached properties - adds complexity and code-behind
  2. Extending DataGridRow and using reflection to access internal properties - fragile and maintenance-heavy
  3. Manual styling in code-behind - violates MVVM pattern
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions