簡體   English   中英

Windows Phone 7中似乎無法從TouchPanel獲得觸摸輸入

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM