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

发布于 2024-10-14 19:05:46 字数 317 浏览 5 评论 0原文

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

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

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

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).

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怪我太投入 2024-10-21 19:05:46

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

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

然后,在 银光项目。在 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);
}

Here is how I set it up - in the page constructor I set the gesture type:

// Constructor
public MainPage()
{
    InitializeComponent();
    TouchPanel.EnabledGestures = GestureType.Tap;
}

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

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

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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文