鼠标双击触摸 ScatterViewItem
我开发了一个 WPF4 触摸应用程序,它使用一些 Microsoft Surface 控件。我想捕获 ScatterViewItem 上的 MouseDoubleClick 事件。当我使用鼠标时该事件会触发,但是当我使用手指时,该事件永远不会引发。为什么 ?
多谢。
更新:
我最终编写了这段代码,在有限的矩形(16px 宽度和高度)上重现 TouchLeave 事件的简单双击,并在 2 个 TouchLeave 事件之间所需的时间为 500 毫秒。该代码尚未优化,但它可以工作,如果您有任何意见,请不要犹豫:)
private bool _doubleHasTimeAndPos = false;
private TimeSpan? _doubleTouchTime = null;
private Point? _doubleTouchPoint = null;
private void ScatterViewItem_TouchLeave(object sender, TouchEventArgs e)
{
if (!this._doubleHasTimeAndPos)
{
this._doubleTouchTime = DateTime.Now.TimeOfDay;
this._doubleTouchPoint = e.GetTouchPoint(this.scatterView).Position;
this._doubleHasTimeAndPos = true;
}
else
{
if (DateTime.Now.TimeOfDay.Subtract(this._doubleTouchTime.Value).TotalMilliseconds <= 500)
{
Point touchPoint = e.GetTouchPoint(this.scatterView).Position;
double xDelta = Math.Abs(this._doubleTouchPoint.Value.X - touchPoint.X);
double yDelta = Math.Abs(this._doubleTouchPoint.Value.Y - touchPoint.Y);
if (xDelta <= 16 && yDelta <= 16)
{
// DOUBLE TAP here !
}
}
this._doubleTouchTime = null;
this._doubleTouchPoint = null;
this._doubleHasTimeAndPos = false;
}
}
I develop a WPF4 touch aplication which use some Microsoft Surface controls. I would like to catch the MouseDoubleClick event on a ScatterViewItem. The event fires when i use the mouse, but when i use my finger, the event is never raised. Why ?
Thanks a lot.
UPDATE :
I finally wrote this code to reproduce a simple double tap with TouchLeave event on a limited rect (16px width & height) and 500ms for the required time between 2 TouchLeave events. This code is not optimized but it works, if you have some remark, don't hesitate :)
private bool _doubleHasTimeAndPos = false;
private TimeSpan? _doubleTouchTime = null;
private Point? _doubleTouchPoint = null;
private void ScatterViewItem_TouchLeave(object sender, TouchEventArgs e)
{
if (!this._doubleHasTimeAndPos)
{
this._doubleTouchTime = DateTime.Now.TimeOfDay;
this._doubleTouchPoint = e.GetTouchPoint(this.scatterView).Position;
this._doubleHasTimeAndPos = true;
}
else
{
if (DateTime.Now.TimeOfDay.Subtract(this._doubleTouchTime.Value).TotalMilliseconds <= 500)
{
Point touchPoint = e.GetTouchPoint(this.scatterView).Position;
double xDelta = Math.Abs(this._doubleTouchPoint.Value.X - touchPoint.X);
double yDelta = Math.Abs(this._doubleTouchPoint.Value.Y - touchPoint.Y);
if (xDelta <= 16 && yDelta <= 16)
{
// DOUBLE TAP here !
}
}
this._doubleTouchTime = null;
this._doubleTouchPoint = null;
this._doubleHasTimeAndPos = false;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于缺乏触摸基础设施来测试此代码,这只是猜测...
WPF 建议对任何 UIElement 使用 Mouse.MouseDown 附加事件,然后使用 ((MouseButtonEventArgs)e.ClickCount) 检查双击的值 2。
然后
让我知道这是否有效......
Just a guess due to lack of touch infrastructure to test this code ...
WPF recommends using Mouse.MouseDown attached event for any UIElement and then using ((MouseButtonEventArgs)e.ClickCount) to be checked for value 2 for double click.
And then
Let me know if this works....
在 API 级别,触摸事件不会生成双击事件。
此外,微软的 Surface UI 设计指南(免责声明:我帮助编写了它们)实际上强烈建议不要使用“双击”的概念。触摸旨在为用户提供一种更“自然”的与技术交互的方式,而不需要任何培训、文档或记忆“隐藏”功能。双击不是人类在物理世界中进行的交互,也不是任何视觉可供性的东西。因此,不适合在软件应用中使用。苹果同意这一理念,顺便说一句 - 你不会在 iPhone 或 iPad 上看到任何双击交互。
At an API level, touch events will not generate double click events.
Furthermore, Microsoft's Surface UI design guidelines (disclaimer: I helped write them) actually advise strongly against the concept of "double tap". Touch is meant to give user a more 'natural' way of interacting with technology without the need for any traning, documentation, or memorization of 'hidden' features. Double-tap is not an interaction humans do in the physical world and is not something that there are any visual affordances for. Therefore, it is not appropriate to use in software applications. Apple concurs with this philosophy, btw - you won't see any double-tap interactions on the iPhone or iPad.