Preventing swiping between Pivot elements
Asked Answered
C

3

6

I understand this question has been asked before, but never for Windows Phone 8 has it been answered.

In Windows Phone 7, it was possible to set isHitTestVisible = false on the base Pivot element to stop the PivotItem from scrolling when swiping over certain elements, like Sliders and TextBoxes. In Windows Phone 8, however, the Pivot beings scrolling before the ManipulationStarted event (or even the Touch object's events) fires. This means that one cannot prevent scrolling between Pivots by listening for ManipulationStarted on certain Controls like one could in Windows Phone 7.

Is there any way to disable scrolling over certain elements, or even certain sections of the screen?

Carbolize answered 10/6, 2013 at 21:58 Comment(10)
I tried to reproduce you case and found that the Slider control works well within a Pivot control: I can change the Slider value without scrolling between Pivots. What is the problem you have with the Slider?Multipara
Are you using more than one Pivot? Are you sliding (instead of just tapping) to change the value of the slider? The problem only arises when one tries to drag the slider when there exist multiple pivots,Carbolize
By "more than one Pivot", do you mean a Pivot inside of another pivot? Or like a Pivot on the top half of the screen and another on the bottom?Sunlight
Neither: more than one PivotItem within a single Pivot. In that item would be placed a Slider control.Carbolize
not long ago i had a similar problem what solve it was this post geekchamp.com/tips/… works nicely in WP8Unclinch
@SeeSharp I mentioned this fix in the question. It sadly only works in WP7. WP8 is different in how it handles manipulation events and this breaks it.Carbolize
@EricDand I think you're asking the wrong question here. Why do you want to disable swiping? Why not just not use a pivot control at all?Germaine
@ClausJørgensen as Martin said when he put the bounty on the question, I am aware it's against the guidelines. There are times when the guidelines must be violated though, and being able to use a Slider in a Pivot is something I've come across fairly frequently.Carbolize
Right, but in that case, my answer should cover the scenario.Germaine
It does! And I accepted your answer. :) Thanks a bunch-- I had no idea about the whole UseOptimizedmanipulationRouting option.Carbolize
D
14

If your actual problem is that the Pivot swallow manipulation events for map/slider/etc. controls, try set UseOptimizedManipulationRouting="False".

MSDN have a longer explanation of this property.

Otherwise the correct approach is to use Pivot.IsLocked="True".

Dele answered 3/8, 2013 at 11:13 Comment(1)
Setting UseOptimizedManipulationRouting to false will help. But don't forget about e.Handle = true in your control's event handler.Shortly
C
3

For UWP I wanted to use Pivot more like tabs control so I'd to override the pivot style and there is an element Pivot Panel so if we disable ManipulationMode=None swipe will be disabled and it'll work more like tabs.

<PivotPanel x:Name="Panel" VerticalAlignment="Stretch" ManipulationMode="None">
Capricecapricious answered 5/6, 2016 at 11:26 Comment(0)
E
0

I suggest you using WP Silverlight Tolkit, they provide nice gesture events, and you'r event is WhenFlicked().

xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
<toolkit:GestureService.GestureListener>
    <toolkit:GestureListener Flick="WhenFlicked"/>
</toolkit:GestureService.GestureListener>

Function:

if (e.Direction.ToString() == "Horizontal") //Left or right
            {
                if (e.HorizontalVelocity > 0) //Right
                {
                    Pivot.CurrentItem=Pivot.CurrentItem+1; //don't remember the code for changing the page...
                }
                else //Left
                {
                    Pivot.CurrentItem=Pivot.CurrentItem-1;
                }
            }

I also tried writing my swipe event, but this one is way better and doesn't trigger events of elements placed on the page. Good Luck

Exocrine answered 2/8, 2013 at 6:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.