How would I add an MouseDoubleClick event on my DatagridTemplateColumn?
My Column:
<DataGridTemplateColumn Header="PK">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Name="pk" HorizontalAlignment="Center" Stretch="None" />
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=Primary_Key}" Value="J">
<Setter TargetName="pk" Property="Source" Value="/UserInterface;component/Resources/Images/key.png"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
I now do it with an MouseDoubleClick Event on the DataGrid itself, but this offcourse fires on every doubleclick on any cell :
Private Sub dgColumns_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseButtonEventArgs)
Dim dg As DataGrid = CType(sender, DataGrid)
If dg.SelectedItem IsNot Nothing AndAlso dg.SelectedItem.GetType Is GetType(Attribuut) Then
If CType(dg.SelectedItem, Attribuut).Primary_Key = "J" Then
CType(dg.SelectedItem, Attribuut).Primary_Key = "N"
Else
CType(dg.SelectedItem, Attribuut).Primary_Key = "J"
End If
End If
End Sub
This makes the column Image change, but only when I leave the cell, how would I do this instantaneously?
I would suggest to wrap your Image in ContentControl. ContentControl is a subclass of Control. MouseDoubleClick is defined in the Control class.