Ize
Ize

Reputation: 149

Handling keyboard-input without any input-element. (Xaml, WinRT)

In my WinRT application it's possible for the user to loop over some strings in a textblock.

private void contentGrid_Tapped(object sender, TappedRoutedEventArgs e)
    {
        if (e.OriginalSource.Equals(contentGrid) || e.OriginalSource.Equals(contentBlock))
        {                
            ShowNextItem();               
        }
    }

When debugging I simply mouse-click to emulate a finger-tapp. But I'd like the user to be able to press the spacebar in order to invoke "ShowNextItem()" if they use a desktop rather than a touch-orientated device.

I know how to write keydown-events for textboxes and tried to make one for my textblock. Curiously enough, all input except tapping is ignored.

Does anyone have any idea why?

Upvotes: 0

Views: 617

Answers (1)

Filip Skakun
Filip Skakun

Reputation: 31724

Only a focused element gets keyboard events. You can listen to all input events globally though - check Window.Current.CoreWindow.KeyDown.

Upvotes: 1

Related Questions