WPF - 检测鼠标按下了设定的时间段 [英] WPF - Detect mouse down for a set period of time
本文介绍了WPF - 检测鼠标按下了设定的时间段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是检测鼠标按键被按住一个特定的元素上的一个特定时期的最佳方法是什么?
what's the best way to detect when a mouse button has been held down on a particular element for a specific period of time?
推荐答案
您需要添加的MouseDown
和的MouseUp
处理的对象。在的MouseDown
记录 DateTime.Now
。如果在的MouseUp
处理程序:
You need to add MouseDown
and MouseUp
handlers to the object. In the MouseDown
record DateTime.Now
. If in the MouseUp
handler:
DateTime.Now.Subtract(clickTime).TotalSeconds > your_seconds_value
则触发一个新的事件 MouseClickedForXseconds
。
如果你不想等待鼠标弹起事件,那么你需要开始对的MouseDown
方法,激发你的 MouseClickedForXSeconds定时器
事件。该定时器将鼠标抬起事件被取消。
If you don't want to wait for a mouse up event then you need to start a timer on the MouseDown
method which fires your MouseClickedForXSeconds
event. This timer will be canceled by a mouse up event.
这篇关于WPF - 检测鼠标按下了设定的时间段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文