如何检测 toolkit:GestureListener Hold 何时停止?
有什么方法可以检测到这一点吗?我想只要用户按住图标就继续执行操作。
Is there a way I can detect this? I want to keep performing an action as long as the user is holding on an icon.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用鼠标操作事件来检测执行操作的时间,而不是使用
GestureListener
。例如:MouseLeftButtonDown
以了解用户何时触摸了图标MouseLeftButtonUp
或MouseLeave
触发,表明用户触摸了图标不再触摸该图标MouseEnter
来启动操作Instead of using the
GestureListener
for this you could instead use the mouse manipulation events to detect how long to perform your action. For instance:MouseLeftButtonDown
to know when the user has touched the iconMouseLeftButtonUp
orMouseLeave
fire indicating that the user is no longer touching that iconMouseEnter
for initiating the action今天我在我的项目中做了同样的事情。我会告诉你我实现的基本逻辑(假设它必须在按钮上完成)。
步骤1:
在按钮_ManipulationStarted_事件上启动一个计时器,在间隔之后,您可以想要触发重复动作。
第 2 步:
在按钮上_ManipulationCompleted_事件停止计时器。
第 3 步:
如果计时器被触发,请停止计时器并启动另一个计时器,其中间隔 = 操作的重复间隔< /strong>。并且在第二个计时器 fire 处理程序中,仅当 control 具有焦点时才执行您的操作。在这种情况下,控件是一个按钮,您可以检查button.IsPressed是否为true,然后执行操作。
代码看起来像:
希望这有帮助。
Today only i did the same thing in my project.I'll tell you the basic logic what i implemented(assuming it has to be done on button).
Step 1:
On the button _ManipulationStarted_ event start a timer with the interval after which you want to fire the repeat action.
Step 2:
On the button _ManipulationCompleted_ event stop the timer.
Step 3:
If the timer is fired,stop the timer and start another timer with interval = the repeat interval for your action.And inside the second timer fire handler perform your operation only if the control has focus. In this case, where the control is a button, you can check if the button.IsPressed is true then perform action.
The code will look something like:
Hope this helps.
注意:Amresh Kumar 建议使用操纵事件是正确的。另外,我在 Windows Phone 应用中心论坛上得到了相同的建议,因此我编辑了这篇文章以反映代码更改。
之前,UX 很不稳定,因为将手指从屏幕上抬起并不总是会触发取消。毫不奇怪,工具包中的 GestureCompleted 代码似乎比鼠标按钮事件更适合触摸屏。
XAML:
代码:
NOTE: Amresh Kumar was correct in suggesting using the manipulation events. Also, I was given the same advice on the Windows Phone App Hubs forums so I've edited this post to reflect the code changes.
Before, the UX was flaky because lifting my finger off the screen didn't always trigger a cancellation. Not surprisingly, the GestureCompleted code in the toolkit appears to be better geared towards touchscreens than are mouse button events.
XAML:
code: