似乎无法从 Windows Phone 7 中的 TouchPanel 获得触摸输入

2024-01-09

我已经在 Visual Studio 中启动了一个新项目,并一直在尝试使用静态 TouchPanel 类来获取输入。我已通过 EnabledGestures 属性启用了“点击”手势,但是当我点击屏幕时,手势未注册(即 TouchPanel.IsGestureAvailable 返回 false)。

其他诸如 Mouse.GetState().LeftButton == ButtonState.Pressed 之类的事情从未被证明是正确的,即使在我之前的项目(基于 Microsoft 示例项目)中它总是可以正常工作而没有任何问题。

有人知道为什么我似乎无法从设备获得任何形式的输入吗?


这是我的设置方法 - 在页面构造函数中我设置手势类型:

// 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);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

似乎无法从 Windows Phone 7 中的 TouchPanel 获得触摸输入 的相关文章

随机推荐