I have a DataGrid
which has a style for IsSelectionActive
; however, as soon as the ContextMenu
opens, the grid loses IsSelectionActive
and it looks like to the user that as if the context menu somehow took the selection and may confuse the user.
Is there a way to retain IsSelectionActive
when a context menu opens?
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<!--<Condition Property="Selector.IsFocused" Value="True" />-->
<Condition Property="IsSelected" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Background" Value="Red" />
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="Selector.IsFocused" Value="False" />
<Condition Property="IsSelected" Value="False" />
</MultiTrigger.Conditions>
<Setter Property="Background" Value="Green" />
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="Selector.IsFocused" Value="False" />
<Condition Property="IsSelected" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Background" Value="Blue" />
</MultiTrigger>
Here is an entire XAML that I used in test application to get your desired behavior:
The key thing that enables this behavior is that if multiple triggers that have conflicting
Setters
are active simultaneously, the last one wins.