这是我的设置方法 - 在页面构造函数中我设置手势类型:
// Constructor
public MainPage()
{
InitializeComponent();
TouchPanel.EnabledGestures = GestureType.Tap;
}
然后,在主网格的 XAML 标记中,我将其链接到 ManipulationCompleted 事件处理程序:
<Grid ManipulationCompleted="LayoutRoot_ManipulationCompleted" x:Name="LayoutRoot" Background="Transparent">
</Grid>
然后,在同一个事件处理程序中:
private void LayoutRoot_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
if (TouchPanel.IsGestureAvailable)
{
if (TouchPanel.ReadGesture().GestureType == GestureType.Tap)
{
Debug.WriteLine("A");
}
}
}
在 Silverlight 项目中为我工作。在 XNA 中,您还必须在构造函数中添加手势类型:
public Game1()
{
graphics = new GraphicsDeviceManager(this);
TargetElapsedTime = TimeSpan.FromTicks(333333);
TouchPanel.EnabledGestures = GestureType.Tap;
}
然后在 Update 方法中你有相同的验证:
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
if (TouchPanel.IsGestureAvailable)
{
if (TouchPanel.ReadGesture().GestureType == GestureType.Tap)
{
Debug.WriteLine("A");
}
}
// TODO: Add your update logic here
base.Update(gameTime);
}