I have the following on a datagrid in my C# code:
<DataGrid.InputBindings>
<MouseBinding Gesture="LeftDoubleClick" Command="{Binding CmdTransUnitFillerRowDblClick}" />
</DataGrid.InputBindings>
It works for the most part except if user first selects the row (single click) and then tries double-clicking the row. In this situation the CmdTransUnitFillerRowDblClick code is never fired for processing.
So, how can I get the CmdTransUnitFillerRowDblClick to fire correctly on a double-click when the row is already selected?
Since someone may ask:
private void ExecutecmdTransUnitFillerRowDblClick(object parameter)
{
if (DgTransUnitFillerSelectedItem != null)
TransUnitFillerDoubleClick(DgTransUnitFillerSelectedItem.CollectionRowId);
}
On top of your existing InputBinding, you can use a Style to attach the InputBinding to each cell:
This requires use of the MouseCommands class from here.
Though I think a cleaner way is to just handle the MouseDoubleClick event in the code-behind and manually raise the Command execution by calling your ViewModel directly, or calling .Execute() on the command.
See my answer to another related question. The problem is that the datagrid no longer has the focus after the user selects a row (or cell, actually); the cell that the user clicked in the datagrid does. So you have to change the focus back to the datagrid to allow this.
Change:
To:
...and add: