As you know you can't bind an Event directly to a command without a behaviour:
<DataGrid>
<i:Interaction.Triggers>
<i:EventTrigger EventName="PreviewMouseDoubleClick">
<i:InvokeCommandAction Command="{Binding TradeEntryCommand"} />
</i:EventTrigger>
</i:Interaction.Triggers>
</DataGrid>
This works perfectly fine, however now I have to refactor this from double clicking the DataGrid itself to double clicking the Cell. (I don't care which cell was clicked)
I was hoping to define this behviour now inside the Cell Style like this:
<Style x:Key="DefaultCellStyleBase" TargetType="{x:Type DataGridCell}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="PreviewMouseDoubleClick">
?????????
</EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<!-- ... -->
</Style>
But how would I bring in the behaviour from above to fire the command?
Highly appreciated,
Since you are retemplating the DataGridCell, you could add the triggers to the root element in the control template. Something like:
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Grid x:Name="root" Background="Transparent">
<i:Interaction.Triggers>
<i:EventTrigger EventName="PreviewMouseDoubleClick">
<i:InvokeCommandAction Command="{Binding TradeEntryCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Grid>
</ControlTemplate>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With