我有一个关于Gesturehandling的问题。
我主要是在这篇教程之后做的:
http://www.nickharris.net/2010/11/using-touchpanel-for-gestures-in-windows-phone-7/
这是我的Remote.xaml文件:
<UserControl x:Class="EnergyRadio.Remote"
....
ManipulationCompleted="StackPanel_ManipulationCompleted">
<Grid x:Name="LayoutRoot" Background="Transparent" >
</Grid>
</UserControl>这是Remote.xaml.cs:
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;
}
}
}无论我如何在手机上滑动手指,它都会让我回到水平方向。但这应该是第一步。我真正需要的是四个方向。这意味着上,下,右,左。
但是我找不到这个手势类型..有没有人有主意?
它应该看起来像这样:
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;
}谢谢。
发布于 2012-03-28 23:23:38
我使用另一种方式来处理手势..不是XNA的方式。你可以试试GestureService.GestureListener
例如,您想要检测矩形内的拖动事件,您可以这样做
<Rectangle x:Name="HelloRect">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragStarted="DragStarted_EventHandler" DragCompleted="DragCompleted_EventHandler" />
</toolkit:GestureService.GestureListener>
</Rectangle>然后,在后台代码中,您可以拥有手势的事件处理程序
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.htm和http://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类型的方向属性
从那里你可以确定轻击的方向
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
https://stackoverflow.com/questions/9909759
复制相似问题