Tech Off Thread

6 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Detect mouse double click in WPF

Back to Forum: Tech Off
  • User profile image
    kaul

    Is there any way to detect whether a wpf control received mouse double click (couldn't find the MouseDoubleClick event)? Actually I am starting a storyboard animation on click of a button (in xaml) and getting wiered behaviour if user performs double click. As far as click (single) is concerned the application is working perfectly fine.

  • User profile image
    Rob Relyea

    http://msdn2.microsoft.com/en-us/library/system.windows.controls.control.mousedoubleclick.aspx points to an event defined on Control (and thus available on Button as well) that may help you.  Also note that ClickCount may help you.

    Thanks, Rob

    Rob Relyea | Program Manager, WPF & Xaml Language Team
    robrelyea.com | /blog | /wpf | /xaml

  • User profile image
    kaul

    Thanks ! Smiley

  • User profile image
    ltawes

    Rob Relyea said:
    http://msdn2.microsoft.com/en-us/library/system.windows.controls.control.mousedoubleclick.aspx points to an event defined on Control (and thus available on Button as well) that may help you.  Also note that ClickCount may help you.

    Thanks, Rob

    Rob Relyea | Program Manager, WPF & Xaml Language Team
    robrelyea.com | /blog | /wpf | /xaml

    Rob,

    The ClickCount fires each time the mouse is clicked.  Thus if you DoubleClick, you will first get a value of 1, followed by a value of 2.  What happens if you have a shape for instance that requires one action when a user single clicks on the shape and a different action when a user DoubleClicks on the same shape?  I've seen a lot of postings with people suggesting the use of select case or an if then else statement but this will never work since even if you DoubleClick you will first get a value of 1.  Even MSDN's sample uses if then, but you're always going to get the value of 1 followed by the value of 2 on DoubleClick.

    Kindest regards,
    -LT

  • User profile image
    figuerres

    ltawes said:
    Rob Relyea said:
    *snip*
    Rob,

    The ClickCount fires each time the mouse is clicked.  Thus if you DoubleClick, you will first get a value of 1, followed by a value of 2.  What happens if you have a shape for instance that requires one action when a user single clicks on the shape and a different action when a user DoubleClicks on the same shape?  I've seen a lot of postings with people suggesting the use of select case or an if then else statement but this will never work since even if you DoubleClick you will first get a value of 1.  Even MSDN's sample uses if then, but you're always going to get the value of 1 followed by the value of 2 on DoubleClick.

    Kindest regards,
    -LT
    I am not rob but I think what has to be done is to have a time frame for counting 2 clicks as a "double click"  + location of the #2 click.

    for example *IF* 2 clicks arraive in less then n seconds and in a rect of size x,y then you have a "double click" event.
    time and rect size need to be adaptable for a number of factors like user might be disabled
    display resoulution -- larger pixel count might need a larger rect.

    things like that....

  • User profile image
    DCMonkey

    ltawes said:
    Rob Relyea said:
    *snip*
    Rob,

    The ClickCount fires each time the mouse is clicked.  Thus if you DoubleClick, you will first get a value of 1, followed by a value of 2.  What happens if you have a shape for instance that requires one action when a user single clicks on the shape and a different action when a user DoubleClicks on the same shape?  I've seen a lot of postings with people suggesting the use of select case or an if then else statement but this will never work since even if you DoubleClick you will first get a value of 1.  Even MSDN's sample uses if then, but you're always going to get the value of 1 followed by the value of 2 on DoubleClick.

    Kindest regards,
    -LT
    Yeah, that's a tough one, but I wonder what these two actions you want to perform are. Usually when you doubleclick on something, the first click selects the item if it is not already selected, and the 2nd click within the doubleclick time window performs some action on the selection. Checking the ClickCount in MouseDown supports that scenario.

    PS: Old thread.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.