ListView ManipulationCompleted 事件在手机上不起作用 [英] ListView ManipulationCompleted event doesn't work on phone

查看:24
本文介绍了ListView ManipulationCompleted 事件在手机上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 10 UWP 应用程序中有此代码:

I have this code in a Windows 10 UWP application:

MyListView.ManipulationMode = ManipulationModes.TranslateX;
MyListView.ManipulationStarted += (s, e) => x1 = (int)e.Position.X;
MyListView.ManipulationCompleted += (s, e) =>
{
    x2 = (int)e.Position.X;
    if (x1 > x2)
    {
        DataController.PaneOpen(false);
    };
    if (x1 < x2)
    {
        DataController.PaneOpen(true);
    };
};

ManipulationCompleted 事件在 ListView 中的手机上不起作用.处理程序中的代码永远不会被调用.在PC上运行良好,但在手机上不起作用.我不明白为什么.

The ManipulationCompleted event doesn't work on phone in ListView. The code inside the handler never gets called. It's working fine on PC, but doesn't work on phone. I don't understand why.

推荐答案

ListView 在 PC 上工作时,我们可以通过滚动鼠标滚轮来滚动它,但在手机上工作时,没有鼠标设备连接到手机,我们实际上是通过滑动滚动ListView.

When a ListView works on PC, we can scroll it by scrolling the wheel of mouse, but when it works on phone, there is no mouse device connected to a phone, we actually scroll the ListView through swiping.

一个 ListView 控件包含一个像这样的 ScrollViewer:

A ListView control contains a ScrollViewer like this:

我觉得问题出在这个ScrollViewer上,在PC上时,它分别处理Scrolling和Manipulation事件,但在手机上时,无法区分滚动事件和操纵.

I think the problem is with this ScrollViewer, when it is on PC, it handles Scrolling and Manipulation events separately, but when it is on a phone, it can't differentiate the events of scrolling and manipulation.

在我看来,这个操作事件可以响应鼠标设备,但不能响应单指触摸.当您使用手机模拟器的单点鼠标输入鼠标模式时,如果我们在移动模拟器和模拟器上测试ListView就更清楚了.模拟器,操作事件正常工作,但是当您使用移动模拟器的Single Point Touch Input 或模拟器的Basic Touch Mode 时,它不起作用.有趣的是,当我们使用 Multi-Touch Input 时,操作事件实际上在移动模拟器上仍然可以正常工作.更有趣的是,使用操作事件 说:

In my view, this manipulation event can respond to Mouse device, but not to single finger touch. It is clearer if we test a ListView on Mobile Emulator and simulator, when you use Single Point Mouse Input of a phone emulator or Mouse Mode of simulator, the manipulation events works fine, but when you use Single Point Touch Input of mobile emulator or Basic Touch Mode of simulator, it doesn't work. Interesting thing is, the manipulation events actually still works fine on a mobile emulator when we use Multi-Touch Input. More interesting thing is, the official docs of Using manipulation events says:

如果您没有触摸屏显示器,您可以使用鼠标和鼠标滚轮界面在模拟器中测试您的操作事件代码.

If you don't have a touch-screen monitor, you can test your manipulation event code in the simulator using a mouse and mouse wheel interface.

所以,它应该可以在真正的手机上运行.由于我现在没有任何设备,我无法判断它在真实手机上是否可以正常工作,我会在设备上测试后更新我的答案.

So, it's supposed to work on a real phone. Since I don't have any device by now, I can't tell if it works fine on a real phone, I will update my answer after I test it on device.

但是,我们仍然可以通过像这样处理Pointer的事件来操作手机上的ListView:

But, we can still manipulate a ListView on a phone by handling the events of Pointer like this:

<ListView x:Name="MyListView" PointerCanceled="PointerExisted" PointerEntered="PointerEntered" PointerMoved="PointerMoved" PointerExited="PointerExisted">

经过测试,在 PC 和手机上都可以正常工作.

Tested it, it works fine both on PC and phone.

更新:

刚刚在X1 Carbon,Lumia950上测试,发现Manipulation事件会用两根手指触发,结果和在手机模拟器上一样.

Just tested on X1 Carbon, Lumia950, I found that the Manipulation event will be triggered using two fingers, the result is same as it was on mobile emulator.

这篇关于ListView ManipulationCompleted 事件在手机上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆