[英]Can't seem to get touch input from TouchPanel in Windows Phone 7
我已经在Visual Studio中启动了一个新项目,并一直在尝试使用静态TouchPanel类来获取输入。 我已经通过EnabledGestures属性启用了“ Tap”手势,但是,当我点击屏幕时,手势未注册(即TouchPanel.IsGestureAvailable返回false)。
即使在我之前的项目(基于Microsoft示例项目)中,Mouse.GetState()。LeftButton == ButtonState.Pressed之类的其他东西也从来没有被证明是正确的,但是它始终可以正常工作。
任何人都有想法,为什么我似乎无法从设备获得任何形式的输入?
这是我的设置方法-在页面构造函数中,我设置了手势类型:
// 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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.