Question

I have n number of pivot items . How to stop scrolling from last to first item. Any help will be greatly appreciated.

Était-ce utile?

La solution

I'm not sure if that would work, hence as Ulugbek Umirov said in comments - it is dependant on OS version. I don't have emulator right now to try, but you may try to do it like this:

public MainPage()
{
   InitializeComponent();
   myPivot.IsHitTestVisible = false; // disable your Pivot
   Touch.FrameReported += Touch_FrameReported;
   TouchPanel.EnabledGestures = GestureType.HorizontalDrag; 
}

TouchPoint first;
private const int detectRightGesture = 20;

private void Touch_FrameReported(object sender, TouchFrameEventArgs e)
{
    TouchPoint mainTouch = e.GetPrimaryTouchPoint(this);
    if (mainTouch.Action == TouchAction.Down)
        first = mainTouch;
    else if (mainTouch.Action == TouchAction.Up && TouchPanel.IsGestureAvailable)
    {
        if (mainTouch.Position.X - first.Position.X < -detectRightGesture)
        {
            if (myPivot.SelectedIndex < myPivot.Items.Count - 1)
                myPivot.SelectedIndex++;
        }
        else if (mainTouch.Position.X - first.Position.X > detectRightGesture)
        {
            if (myPivot.SelectedIndex > 0)
                myPivot.SelectedIndex--;
        }
    }
}

According to MSDN - TouchPanel should be available from WP7.1 and Touch.FrameReported Event should be available on WP7.0. Therefore there is a chance that it will work.

You have to add reference to Microsoft.Xna.Framework.Input.Touch assembly.

I've also added detectRightGesture so that Pivot won't be switched on small vertical drags, it's a matter of test if that will be needed.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top