#658 – An Easier Way to Handle Mouse Double Clicks

You can detect mouse double clicks on user interface elements by handling one of the the mouse button events (e.g. MouseDown) on the element and checking to see if the MouseButtonEventArgs.ClickCount property has a value of 2.  The various mouse button events are defined for anything that derives from UIElement or ContentElement.

If your user interface element derives from Control, you can instead just handle the MouseDoubleClick (or PreviewMouseDoubleClick) event.

The sequence of events that fire when the user double-clicks a control with the left mouse button is shown below.  (For simplicity, I’m omitting the MouseLeftButtonDown and MouseLeftButtonUp events and their associated preview events.

  • PreviewMouseDown, with ClickCount = 1
  • MouseDown, with ClickCount = 1
  • PreviewMouseUp
  • MouseUp
  • PreviewMouseDoubleClick
  • PreviewMouseDown, with ClickCount = 2
  • MouseDoubleClick
  • MouseDown, with ClickCount = 2
  • PreviewMouseUp
  • MouseUp

The MouseDoubleClick event does send an instance of MouseButtonEventArgs, but its ClickCount property will always be equal to 1.