似乎无法摆脱的TouchPanel触摸输入的Windows Phone 7 [英] Can't seem to get touch input from TouchPanel in Windows Phone 7
问题描述
我已经开始在Visual Studio中一个新的项目,并已试图用静态的TouchPanel类来获得输入。我已经启用通过EnabledGestures属性'点击'的姿态,但是当我点击屏幕手势不登记(即TouchPanel.IsGestureAvailable返回false)。
I've started a new project in Visual Studio and have been trying to use the static TouchPanel class to get input. I have enabled the 'Tap' gesture through the EnabledGestures property, however when I tap the screen the gesture does not register (i.e. TouchPanel.IsGestureAvailable returns false).
其他的事情如Mouse.GetState()。LeftButton == ButtonState.Pressed永远不要证明是正确的,即使在我以前的项目(这是基于微软样本项目),它总是工作没有任何问题。
Other things such as Mouse.GetState().LeftButton == ButtonState.Pressed do not ever prove true even though in my previous project (which was based on a Microsoft sample project) it always worked without any problems.
任何人有任何想法,为什么我不能似乎能够从设备得到任何形式的输入?
Anyone have any ideas why I can't seem to be able to get any form of input from the device?
推荐答案
下面是我如何设置它 - 在页面构造函数中我设置的动作类型:
Here is how I set it up - in the page constructor I set the gesture type:
// Constructor
public MainPage()
{
InitializeComponent();
TouchPanel.EnabledGestures = GestureType.Tap;
}
然后,在XAML标记为格主我把它链接到一个在ManipulationCompleted事件处理程序:
Then, in the XAML markup for the main grid I link it to a ManipulationCompleted event handler:
<Grid ManipulationCompleted="LayoutRoot_ManipulationCompleted" x:Name="LayoutRoot" Background="Transparent">
</Grid>
然后,在相同的事件处理程序:
Then, in the same event handler:
private void LayoutRoot_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
if (TouchPanel.IsGestureAvailable)
{
if (TouchPanel.ReadGesture().GestureType == GestureType.Tap)
{
Debug.WriteLine("A");
}
}
}
在Silverlight对我的作品项目。在XNA,你必须还添加了手势类型的构造器:
Works for me in a Silverlight project. In XNA, you would have to add the gesture types also in the constructor:
public Game1()
{
graphics = new GraphicsDeviceManager(this);
TargetElapsedTime = TimeSpan.FromTicks(333333);
TouchPanel.EnabledGestures = GestureType.Tap;
}
然后在Update方法你有相同的验证b
$ b
Then in the Update method you have the same verification:
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);
}
这篇关于似乎无法摆脱的TouchPanel触摸输入的Windows Phone 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!