1

我找不到有关如何在 ScatterViewItems 上接收自定义手势的信息。我希望“点击并按住”在模板后面的类中调用一个函数。

4

2 回答 2

0

以下链接是如何使用“WndProc”接收触摸手势 Win32 消息,但示例是 C++

http://msdn.microsoft.com/en-us/library/windows/desktop/dd371578(v=vs.85).aspx

另一种方法是使用简单的“DispatcherTimer”实际实现 Tap-Hold 手势,该手势应在您想要应用手势的元素的“PreviewTouchDown”事件处理程序中按下“ScatterViewItem”时启动。

void OnPreviewTouchDown(object sender, System.Windows.Input.TouchEventArgs e)
{
if(e.Source.GetHashCode() == YourUIElement.GetHashCode() )
{ 
MyTimer.Start();

//You need to capture the touch before the ScatterViewItem handles its own touch which will    
//block you from receiving the touch up event 
YourUIElement.CaptureTouch(e.TouchDevice);
e.Handled = true;

}
}

void OnPreviewTouchUp(object sender, System.Windows.Input.TouchEventArgs e)
{
YourUIElement.ReleaseAllTouches();
}


private void OnTimerTick(object sender, EventArgs e)
{
// To call whatever function or do whatever action you need.
IsTapHoldGestureOkay = true;
DoStuff();
MyTimer.Stop();
}
于 2011-12-14T10:46:30.723 回答
0
TouchExtensions.AddTapGestureHandler(your_object_that_willdetect, your_handler_function);

有点晚但没有伤害=)

于 2014-01-16T12:38:09.207 回答