tavier
tavier

Reputation: 1794

Overriding Manipulation Events on PivotItem

I have a UWP app where I am using a pivot control with a collection of pivot items. Now, my requirement is to capture the swipe down/up gestures on the pivot item. I have done something like below:

<Pivot>
    <PivotItem Header="jdslj" ManipulationMode="All" ManipulationStarted="UIElement_OnManipulationStarted" ManipulationDelta="UIElement_OnManipulationDelta"></PivotItem>
    <PivotItem Header="weew" ManipulationMode="All" ManipulationStarted="UIElement_OnManipulationStarted" ManipulationDelta="UIElement_OnManipulationDelta"></PivotItem>
    <PivotItem Header="332" ManipulationMode="All" ManipulationStarted="UIElement_OnManipulationStarted" ManipulationDelta="UIElement_OnManipulationDelta"></PivotItem>
</Pivot>

Problem is, when I do it, it overrides the behaviour of pivot control and now I am not able to swipe left/right to change the pivot item.

Is there anything I can do to achieve both at the same time?

Upvotes: 0

Views: 244

Answers (1)

Grace Feng
Grace Feng

Reputation: 16652

As we've discussed, we can use the Pointer events to do this work, but only part of them work on mobile device in this scenario(on PC they work fine, you can have a try).

Here is my sample:

<Grid x:Name="rootGrid" Background="White" PointerPressed="Grid_PointerEntered"
      PointerEntered="Grid_PointerEntered" PointerMoved="Grid_PointerMoved">
    <Pivot x:Name="pivot">
        <PivotItem Header="jdslj">
            <TextBlock Name="textBlock" />
        </PivotItem>
        <PivotItem Header="weew">
        </PivotItem>
        <PivotItem Header="332">
        </PivotItem>
    </Pivot>
</Grid>

code behind:

private double Y;
private double deltaY;

private void Grid_PointerEntered(object sender, PointerRoutedEventArgs e)
{
    var pointer = e.GetCurrentPoint(rootGrid);
    Y = pointer.Position.Y;
}

private void Grid_PointerMoved(object sender, PointerRoutedEventArgs e)
{
    var pointer = e.GetCurrentPoint(rootGrid);
    deltaY = pointer.Position.Y;
    if ((deltaY - Y) > 30)
    {
        textBlock.Text = "down";
        Y = 0;
        deltaY = 0;
    }
    else if ((Y - deltaY) > 30)
    {
        textBlock.Text = "up";
        Y = 0;
        deltaY = 0;
    }
}

Since you asked for a sample, I posted this answer, but I want to say again, my sample works, but not very sensitive.

Upvotes: 1

Related Questions