wpf wpf中鼠标双击和鼠标点击的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1631906/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 21:08:16  来源:igfitidea点击:

Distinguish between mouse doubleclick and mouse click in wpf

wpfmouseeventdouble-click

提问by Ghassan Karwchan

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?

在我的 WPF 应用程序中,我使用的是 ListView GridView,并且我实现了一个与鼠标双击相关联的功能。有没有区分鼠标双击和鼠标单击的方法或控件?

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

我使用了一个按钮,并为mousedoubleclick 实现了一个事件,但仍然触发了click 事件

Thanks for help

感谢帮助

采纳答案by Jorge Israel Pe?a

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

看来您只是添加了MouseDoubleClick=属性。检查这些链接:

Sorry if I misunderstood your question.

对不起,如果我误解了你的问题。

回答by mcwyrm

Handling the double click event for controls that present the MouseDoubleClickevent is no trick. Handling double click for other controls involves inspecting the ClickCountproperty of the MouseButtonEventArgs.

处理呈现事件的控件的双击MouseDoubleClick事件并不是什么技巧。处理双击其他控件涉及检查ClickCount的财产MouseButtonEventArgs

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

因此,例如,您的 XAML 可能如下所示:

<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'sa page that provides a somewhat more detailed example.

这是一个提供更详细示例的页面。