3
votes

I have a WPF Datagrid showing data. For each item displayed in the DataGrid, the item can be expanded to display detail data shown using the RowDetailsTemplate. Both the DataGrid Row and the RowDetailsTemplate handle the Double Click event.

The problem is when double clicking on the RowDetailsTemplate, the double click event is correctly fired, but the double click event for the parent Row is ALSO fired. This is undesired behaviour.

Does anyone know how to resolve this so that double clicking on the RowDetailTemplate only fired the RowDetailsTemplate double click event and not also it's parent Row double click event?

2

2 Answers

2
votes

I encountered this and observed two events, so setting e.Handled to true did not help.

I couldn't find a better solution than to keep a boolean 'lock' variable:

private bool lockDoubleClick;

private void dgParent_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
    if (lockDoubleClick) return;
    // parent was double-clicked; do something
}

private void dgChild_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
    lockDoubleClick = true;
    // child was double-clicked; do something
    Dispatcher.BeginInvoke(new Action(() => lockDoubleClick = false));
}
1
votes

The event is probably bubbling, you could try setting

e.Handled = true;

in the row details double click handler to prevent the handling by parent controls.