【问题标题】:Tap-And-Hold Event on ScatterViewItemScatterViewItem 上的点击并按住事件
【发布时间】:2010-09-10 12:19:30
【问题描述】:

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

【问题讨论】:

    标签: c# wpf pixelsense


    【解决方案1】:

    以下链接是如何使用“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();
    }
    

    【讨论】:

      【解决方案2】:
      TouchExtensions.AddTapGestureHandler(your_object_that_willdetect, your_handler_function);
      

      有点晚但没有坏处=)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-03-24
        • 2017-11-29
        • 2011-03-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多