检测枢轴中的滑动方向

Ano*_*eek 2 pivot windows-phone-8

我在Windows Phone 8中工作,我在Pivot控件中有两个枢轴项.如何检测我是向右还是向左滑动?

Pra*_*ani 6

步骤1:在解决方案中添加Microsoft.Phone.Controls.Toolkit

Step2:在xaml中添加Microsoft.Phone.Controls.Toolkit引用,如下所示:

xmlns:tolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
Run Code Online (Sandbox Code Playgroud)

Step3:创建手势监听器轻弹事件,如下所示:

<Grid x:Name="LayoutRoot" Background="Transparent">
        <tolkit:GestureService.GestureListener>
            <tolkit:GestureListener Flick="GestureListener_Flick"></tolkit:GestureListener>
        </tolkit:GestureService.GestureListener>
        <!--Pivot Control-->
        <controls:Pivot Title="MY APPLICATION">
            <!--Pivot item one-->
            <controls:PivotItem Header="item1">
                <Grid/>
            </controls:PivotItem>

            <!--Pivot item two-->
            <controls:PivotItem Header="item2">
                <Grid/>
            </controls:PivotItem>
        </controls:Pivot>
    </Grid>
Run Code Online (Sandbox Code Playgroud)

第4步:在您的cs页面中添加以下代码:

 private void GestureListener_Flick(object sender, FlickGestureEventArgs e)
        {
            if (e.Direction.ToString() == "Horizontal") //Left or right
            {
                if (e.HorizontalVelocity > 0) //Right
                {

                }
                else //Left
                {

                }
            }
        }
Run Code Online (Sandbox Code Playgroud)

你可以从这里下载工具包