Ghassan Karwchan
Ghassan Karwchan

Reputation: 3530

Distinguish between mouse doubleclick and mouse click in wpf

In my WPF application , I am using ListView GridView, and I implemented a functionality that is associated to mouse double click. Is there a way, or a control that distinguish between the mouse double click and mouse click?

I used a button, and implemented an event for mousedoubleclick, but the click event is still triggering

Thanks for help

Upvotes: 17

Views: 36668

Answers (2)

mcwyrm
mcwyrm

Reputation: 1693

Handling the double click event for controls that present the MouseDoubleClick event is no trick. Handling double click for other controls involves inspecting the ClickCount property of the MouseButtonEventArgs.

So, for instance, your XAML might look something like this:

<SomeControl MouseDown="MyMouseDownHandler">
    ...
</SomeControl>

... and your code behind like this:

private void MyMouseDownHandler(object sender, MouseButtonEventArgs e)
{
    if (e.ClickCount == 2)
    {
        // Handle double-click
    }
}

Here's a page that provides a somewhat more detailed example.

Upvotes: 41

Jorge Israel Pe&#241;a
Jorge Israel Pe&#241;a

Reputation: 38576

It seems you just add the MouseDoubleClick= attribute. Check these links out:

Sorry if I misunderstood your question.

Upvotes: 3

Related Questions