How to get IsSelectionActive for WPF DataGrid?
c#, css-selectors, datagrid, wpf
Solution
IsSelectionActive is an attached property. I think you need to use
<Condition Property="Selector.IsSelectionActive" Value="False" />
This simplified style works for me:
<Style x:Key="CellStyle" TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="Selector.IsSelectionActive" Value="False" />
<Condition Property="IsSelected" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Background" Value="Red"/>
</MultiTrigger>
</Style.Triggers>
</Style>
Problem
I am trying to get `IsSelectionActive` to work with the WPF DataGrid: ``` <Style TargetType="{x:Type DataGridCell}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type DataGridCell}"> <ContentPresenter /> <ControlTemplate.Triggers> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsSelectionActive" Value="False" /> <Condition Property="IsSelected" Value="True" /> <!--<Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGridRow}}, Path=IsSelected}" Value="True" /> <Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}, Path=IsKeyboardFocusWithin}" Value="True" />--> </MultiTrigger.Conditions> ``` Basically, when the focus is lost for the grid, but the selection still remains, I want to apply some styling. Unfortunately, `IsSelectionActive` throws an error that it does not exist in the WPF data grid for some reason.