首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WP7 TouchPanel手势处理

WP7 TouchPanel手势处理
EN

Stack Overflow用户
提问于 2012-03-28 22:36:17
回答 1查看 1.3K关注 0票数 1

我有一个关于Gesturehandling的问题。

我主要是在这篇教程之后做的:

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

这是我的Remote.xaml文件:

代码语言:javascript
复制
 <UserControl x:Class="EnergyRadio.Remote"
 ....
 ManipulationCompleted="StackPanel_ManipulationCompleted">
      <Grid x:Name="LayoutRoot" Background="Transparent" >
      </Grid>
</UserControl>

这是Remote.xaml.cs:

代码语言:javascript
复制
 public Remote()
    {
        InitializeComponent();
        TouchPanel.EnabledGestures = GestureType.VerticalDrag | GestureType.HorizontalDrag;
    }

    private void StackPanel_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
    {
        //Check if touch Gesture is available  
        if (TouchPanel.IsGestureAvailable)
        {
            // Read the gesture so that you can handle the gesture type  
            GestureSample gesture = TouchPanel.ReadGesture();
            switch (gesture.GestureType)
            {
                case GestureType.VerticalDrag:
                    MessageBox.Show("vertikal");
                    break;
                case GestureType.HorizontalDrag:
                    MessageBox.Show("horizontal");
                    break;
                default:
                    //do something  
                    break;
            }
        }
    }

无论我如何在手机上滑动手指,它都会让我回到水平方向。但这应该是第一步。我真正需要的是四个方向。这意味着上,下,右,左。

但是我找不到这个手势类型..有没有人有主意?

它应该看起来像这样:

代码语言:javascript
复制
            switch (gesture.GestureType)
            {
                case "GesturType.Up":
                    MessageBox.Show("Volume Up");
                    break;
                case "GesturType.Down":
                    MessageBox.Show("Volume Down");
                    break;
                case "GesturType.Right":
                    MessageBox.Show("Next Channel");
                    break;
                case "GesturType.Left":
                    MessageBox.Show("Previous Channel");
                    break;
                default:
                    //do something  
                    break;
            }

谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-28 23:23:38

我使用另一种方式来处理手势..不是XNA的方式。你可以试试GestureService.GestureListener

例如,您想要检测矩形内的拖动事件,您可以这样做

代码语言:javascript
复制
   <Rectangle x:Name="HelloRect">
      <toolkit:GestureService.GestureListener>
        <toolkit:GestureListener DragStarted="DragStarted_EventHandler"  DragCompleted="DragCompleted_EventHandler" />
      </toolkit:GestureService.GestureListener>
   </Rectangle>

然后,在后台代码中,您可以拥有手势的事件处理程序

代码语言:javascript
复制
private void DragStarted_EventHandler(object sender, DragStartedGestureEventArgs e)
{
    this.HelloRect.Fill = new SolidColorBrush(Colors.White);
}

private void DragCompleted_EventHandler(object sender, DragCompletedGestureEventArgs e)
{
    this.HelloRect.Fill = new SolidColorBrush(Colors.Black);
}

更新:这个教程很好:http://windowsphonegeek.com/articles/WP7-GestureService-in-depth--key-concepts-and-API

您可能需要检查一些引用,以了解您将获得的事件参数:http://www.mindscapehq.com/Help/PhoneElements/html/2f4dc2f0-f612-6a89-092e-f65c243caded.htmhttp://www.mindscapehq.com/Help/PhoneElements/html/96092851-e003-6423-389c-58d16281122b.htm

还有一个可以查看的拖动增量事件。希望这对你有任何帮助..我对触摸屏thing..sorry不是很熟悉..你可能想要等待更多的回复

从拖动开始和拖动结束坐标可以推断拖动的方向

..I认为你在调查flick事件..另一个很好的教程

http://johnhforrest.com/2010/09/windows-phone-7-gestures/

再次更新: FlickGestureEventArgs包含System.Windows.Controls.Orientation http://msdn.microsoft.com/en-us/library/system.windows.controls.orientation.aspx类型的方向属性

从那里你可以确定轻击的方向

代码语言:javascript
复制
private void Flick_EventHandler(object sender, FlickGestureEventArgs e)
{
    if (e.Direction == Orientation.Horizontal)
    {
        if (e.HorizontalVelocity < 0)
        {
            //Right flick
        }
        else
        {
            //Left flick
        }
    }
    else
    {
        if (e.VerticalVelocity < 0)
        {
            //Up flick
        }
        else
        {
            //Down flick
        }
    }
}

祝你好运,祝你晚上好。

更新:

我刚看到你不应该在GestureType枚举中使用switch case...它们是整型

有关手势类型的列表,请参见

http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.touch.gesturetype.aspx

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9909759

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档