wp7 horizontal swipe selection

2020-03-03 07:36发布

问题:

I'm looking for a control that allows me to swipe through a list of items. Swiping horizontally would move between the next and previous items. The control would also ensure the selected item is moved to the center when not being manipulated. This control will only take up half of the page and I'd like the options to the left and right to be visible and wrap around.

Like so

  <-->
*][**][*

So my question is, does a control like this already exists and if so what is it called?

回答1:

This is super easy if you use the GestureService from the Silverlight Toolkit. Simply implement a handler for the Flick event, and analyse the directory and velocity.

XAML

<toolkit:GestureService.GestureListener>
    <toolkit:GestureListener Flick="GestureListener_Flick" />
</toolkit:GestureService.GestureListener>

C#

private void GestureListener_Flick(object sender, FlickGestureEventArgs e)
{
    if (e.Direction == System.Windows.Controls.Orientation.Horizontal)
    {
        if (e.HorizontalVelocity < 0)
        {
            // flick right
        }
        else
        {
            // flick left
        }
    }
    else
    {
        if (e.VerticalVelocity < 0)
        {
            // flick up
        }
        else
        {
            // flick down
        }
    }
}


回答2:

There is no standard control which meets this description.

If you really want this then you'll have to create it yourself.