ListView ManipulationCompleted event doesn't work on phone

元气小坏坏 提交于 2020-02-14 02:48:30

问题


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);
    };
};

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.


回答1:


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.

A ListView control contains a ScrollViewer like this:

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.

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.

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">

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

Update:

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.



来源:https://stackoverflow.com/questions/35200600/listview-manipulationcompleted-event-doesnt-work-on-phone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!