Aiguil Leblanc
Aiguil Leblanc

Reputation: 186

Highlight the RowDetails in a DataGrid when row is selected

I have a DataGrid with RowDetailsVisibilityMode set to Visible. Now when I select a row I would like to highlight the details area too, while the default is that only row cells are highlighted. Any hint to get this kind of behavior?

Upvotes: 4

Views: 1171

Answers (2)

g1ga
g1ga

Reputation: 322

This worked for me:

<DataGrid.RowDetailsTemplate>
 <DataTemplate>
  <Border>
   <Border.Style>
    <Style TargetType="Border">
      <Style.Triggers>
       <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}}" Value="True">
        <Setter Property="Background" Value="{x:Static SystemColors.HighlightBrush}"/>
      </DataTrigger>
    </Style.Triggers>
   </Style>
   </Border.Style>
   <StackPanel>
     <!-- my details content here --> 
   </StackPanel>
  </Border>
 </DataTemplate>
</DataGrid.RowDetailsTemplate>

Upvotes: 5

DLeh
DLeh

Reputation: 24405

One way you can do this is to have set the RowHeaderWidth. This is the left-most row, when you click on that it selects the whole row, and should show the RowDetails as well.

Another option is to set SelectionUnit="FullRow" on the datagrid, which won't let the user select individual cells, but will instead select the full row and should show the details whenever they click anywhere on the row.

Upvotes: 0

Related Questions