【问题标题】:How to use "gesture" in UWP inkcanvas如何在 UWP inkcanvas 中使用“手势”
【发布时间】:2018-04-04 03:00:41
【问题描述】:

你好我想在inkcanvas上添加一些自定义手势(我做的)功能

但是当 inputdevicetype 是这样的 touch 时,我不知道该怎么做

inkcanvas.InkPresenter.InputDeviceTypes = Windows.UI.Core.CoreInputDeviceTypes.Touch;

当输入设备类型是触摸时,我不能使用任何手势

因为所有输入都被识别出来了

在使用带有触摸输入的 inkcanvas 时,我不能使用手势功能吗?

private void ink1_PointerPressed(object sender, PointerRoutedEventArgs e)
    {            
            PointerDeviceType pointerDevType = e.Pointer.PointerDeviceType;

            pointers = new Dictionary<uint, Windows.UI.Xaml.Input.Pointer>();

            e.Handled = true;

            PointerPoint ptrPt = e.GetCurrentPoint(ink1);
            m_pt.Add(ptrPt);

            if (!pointers.ContainsKey(ptrPt.PointerId))
            {
                // Add contact to dictionary.
                pointers[ptrPt.PointerId] = e.Pointer;
            }               

            switch (ptrPt.PointerDevice.PointerDeviceType)
            {
                case Windows.Devices.Input.PointerDeviceType.Mouse:                       
                    ink1.InkPresenter.InputDeviceTypes = Windows.UI.Core.CoreInputDeviceTypes.Mouse;
                    ink1.RightTapped += ink1_RightTapped;

                    break;

                case PointerDeviceType.Touch:
                    if (m_pt.Count == 2)
                    {                            
                        ink1.InkPresenter.InputDeviceTypes = Windows.UI.Core.CoreInputDeviceTypes.None;
                        ink1.RightTapped += ink1_RightTapped;                          


                    }
                    else if (m_pt.Count == 1 || m_pt.Count > 2)
                    {
                        ink1.InkPresenter.InputDeviceTypes = Windows.UI.Core.CoreInputDeviceTypes.Touch;
                        ink1.RightTapped += ink1_RightTapped;

                    }

                break;

            }         


    }

当我用 2 个手指按下我的 ink1(inkcanvas) 时,我想使用我的手势功能(绘制字母 L 或点击 inkcanvas 3 次)我所做的

比如uwp的doubletapped,righttapped等

【问题讨论】:

  • “我不能使用任何手势”,你能举个例子吗?
  • 例如,我可以通过画一个字母“L”来打开一个图像文件,或者当我用两根手指双击时,我可以在 inkcanvas 上打开一个视频文件。
  • 我仍然对您的问题感到困惑。您可以上传一些代码 sn-p,当inputdevicetype 未触摸时可以正常工作。为什么要用 InkCanvas 打开视频文件?

标签: uwp gesture inkcanvas


【解决方案1】:

我看到您使用PointerPress 事件句柄来处理InkCanvas
InkPresenter 的配置决定了InkCanvas 的指针事件处理行为。您必须将InkPresenter.InputDeviceTypes 设置为CoreInputDeviceTypes.None 以便InkCanvas 处理指针事件,否则它们将传递给InkPresenter 对象。

要使用InkPresenter 对象处理指针事件,您必须将RightDragAction 设置为LeaveUnprocessed 以将输入作为UnprocessedInput 传递,以便您的应用进行自定义处理。

inkCanvas.InkPresenter.InputProcessingConfiguration.RightDragAction =  InkInputRightDragAction.LeaveUnprocessed;

详情请参考InkCanvas的备注部分。

【讨论】:

  • 谢谢,我很高兴知道指针事件。而且它只能用于笔、鼠标输入对吗?不触摸输入
  • @Kay,这个答案意味着如果您的输入类型是 pen 或 touch ,您应该如上所述设置。其中包含触摸输入。
猜你喜欢
  • 2018-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-27
相关资源
最近更新 更多