Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListView ManipulationCompleted event doesn't work on phone

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.

like image 783
SYL Avatar asked Feb 04 '16 12:02

SYL


1 Answers

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: enter image description here

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.

like image 163
Grace Feng Avatar answered Oct 10 '22 01:10

Grace Feng