【问题标题】:Can't seem to get touch input from TouchPanel in Windows Phone 7在 Windows Phone 7 中似乎无法从 TouchPanel 获得触摸输入
【发布时间】:2011-01-29 15:47:46
【问题描述】:

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

Mouse.GetState().LeftButton == ButtonState.Pressed 之类的其他内容从未被证明是正确的,即使在我之前的项目(基于 Microsoft 示例项目)中它始终可以正常工作。

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

【问题讨论】:

  • 你是在模拟器还是设备上测试这个?

标签: c# windows-phone-7 input xna touchscreen


【解决方案1】:

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

// 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;
}

然后在更新方法中你有同样的验证:

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);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-03
    • 2021-05-16
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多