The normal convention for UI controls is for selected text, items, or rows to be brightly colored (e.g., bright blue) when the parent control is in focus and desaturated/dim (e.g., pale blue) when the control is out of focus.
In contrast to the ListView/GridView
, the WPF DataGrid
control does not follow this convention by default. Selected rows appear bright even if another control on in the same window is clearly in focus.
I think this should just be a matter of adding a trigger to the DataGridCell
that sets the background to {DynamicResource {x:Static SystemColors.ControlBrushKey}}
if the DataGrid
is out of focus, but I can't figure out which property to check. IsFocused
sounded like what I want, but that doesn't work. IsMouseCaptured
doesn't seem to work either.
Here's the latest trigger I tried:
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition
Binding="{Binding IsSelected}"
Value="True" />
<Condition
Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=wt:DataGrid}, Path=IsFocused}"
Value="False"/>
</MultiDataTrigger.Conditions>
<Setter
Property="BorderBrush"
Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
<Setter
Property="Background"
Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
<Setter
Property="Foreground"
Value="Gray" />
</MultiDataTrigger>
What can I do to make this trigger dim the cell when the cell is selected and the parent control is not in focus?