0
votes

I create a page in Windows Phone 8.1 which with many component inside it(not just a long list, but some other controls), so I use a scrollviewer control to wrap the controls. In the meantime, I need support some gesture in the page, like quickly swipe up/down.

In windows phone 8.1, the ScrollViewer control will handled the manipulationDelta and related event, and will not fired ManipulationDelta event.

After some search, someone mentioned UseOptimizedManipulationRouting will enable scrollviewer raise the event. But the windows phone 8.1 runtime just removed this property. Change ManipulationMode could help to receive the ManipulationDelta event, but it will disable the original scroll behavior of the ScrollViewer itself.

I could understand the ScrollViewer need to interrupt the ManipulationDelta event to improve performance. My question is is there any we or alternate method could help to get gesture when using scroll viewer?

1
You'll probably have to create a custom ScrollViewer which overrides OnManipulationDelta.Nate Diamond
@NateDiamond The problem here is the ScrollViewer class is marked as sealed in Windows Phone 8.1.2power10

1 Answers

1
votes

There is no way to have the gestures handled by both the ScrollViewer and your controls at the same time. The ScrollViewer runs with a parallel system to handle its manipulations.

As you note, children of the ScrollViewer can get manipulation events, but then the ScrollViewer won't do so. If the children don't take up most of the area then a useful pattern is to allow manipulations on the child and scrolling outside of it. This won't work if the manipulatable children take over the whole contents of the ScrollViewer.

The child could try calling ScrollViewer.ChangeView() to have the ScrollViewer scroll along with the translation delta, but that could end up clunky at the edges between your control and the ScrollViewer's. You could avoid the edge by taking over all of the scrolling. If I understand what you are trying to do correctly this is probably where I'd start: take over everything and call ChangeView as needed.

You can cancel the ScrollViewer's manipulations with CancelDirectManipulations, but not the other way around.

The hard part is determining who should handle a given gesture. If you use the GestureRecognizer rather than the Xaml manipulation events then you can decide on PointerPressed which should handle the gesture and either let it pass through to the ScrollViewer or turn off the ScrollViewer. If you need to wait for a PointerMoved to identify the gesture then it's too late.

I discussed this with regards to Windows Store apps in Windows 8 at http://blogs.msdn.com/b/wsdevsol/archive/2013/02/16/where-did-all-my-gestures-go.aspx . A few details are now different, but the general idea is the same for Windows 8.1 and Windows Phone 8.1 Runtime apps with Xaml.