Can't seem to get touch input from TouchPanel in Windows Phone 7

前端 未结 1 389
终归单人心
终归单人心 2021-01-28 20:57

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

相关标签:
1条回答
  • 2021-01-28 21:56

    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);
    }
    
    0 讨论(0)
提交回复
热议问题