#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.

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

One Response to #658 – An Easier Way to Handle Mouse Double Clicks

  1. Pingback: Dew Drop – October 1, 2012 (#1,412) | Alvin Ashcraft's Morning Dew

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: