如何在Windows Phone 7中滑动

Sha*_*een 21 c# silverlight windows-phone-7

我想在Windows Phone 7中刷图像.我从哪里开始?

ind*_*moz 41

您可以使用适用于Windows Phone 7GestureServiceSilverlight Control Toolkit.在你的UI元素中,添加以下代码片段(在WP7项目中引用工具包的DLL之后) -

<toolkit:GestureService.GestureListener>
    <toolkit:GestureListener Flick="OnFlick"/>
</toolkit:GestureService.GestureListener>  
Run Code Online (Sandbox Code Playgroud)

在代码隐藏文件中实现处理程序OnFlick,就像这样 -

private void OnFlick(object sender, FlickGestureEventArgs e)
{
   var vm = DataContext as SelectedCatalogViewModel;
   if (vm != null)
   {
      // User flicked towards left
      if (e.HorizontalVelocity < 0)
      {
         // Load the next image 
         LoadNextPage(null);
      }

      // User flicked towards right
      if (e.HorizontalVelocity > 0)
      {
         // Load the previous image
         LoadPreviousPage();
      }
   }
}
Run Code Online (Sandbox Code Playgroud)

希望这有帮助,indyfromoz

  • 您可能还需要确保水平速度比垂直速度更大(甚至是一个数量级),因此对角线或大多数垂直滑动不会触发`LoadNextPage`和`LoadPreviousPage`方法. (2认同)
  • @ pho79:或检查(e.Direction == System.Windows.Controls.Orientation.Horizo​​ntal) (2认同)

Phi*_*ill 7

如果您不想使用silverlight工具包,可以使用XNA框架.

http://www.nickharris.net/2010/11/using-touchpanel-for-gestures-in-windows-phone-7/


Sor*_*rey 5

试试这个:

using Microsoft.Phone.Controls;

public partial class MyControl
{
    public MyControl()
    {
        InitializeComponent();

        var gl = GestureService.GetGestureListener(asd);
        gl.Flick += new EventHandler<FlickGestureEventArgs>(GestureListener_Flick);
    }

    private void GestureListener_Flick(object sender, FlickGestureEventArgs e)
    {
        if (e.Direction == Orientation.Horizontal)
        {
            if (e.HorizontalVelocity < 0) // determine direction (Right > 0)
            {
                //Some Action
            }
            else
            {
                //Some Action
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)