Is there an equivalent to the PreviewKeyDown
for a Windows Store App? It isn't available.
I have exactly the same problem as described here:
I have a ListBox with a TextBox above it. I would like to use the arrow keys to navigate from the ListBox to the TextBox. The intention is that if the first item in the ListBox is selected, and the user keys up, the TextBox will get focus.
Ah, tricky. Handling key events isn't super-obvious. Here's what you want:
public MainPage()
{
this.InitializeComponent();
Window.Current.CoreWindow.Dispatcher.AcceleratorKeyActivated += (s, args) =>
{
if ((args.EventType == CoreAcceleratorKeyEventType.SystemKeyDown
|| args.EventType == CoreAcceleratorKeyEventType.KeyDown)
&& (args.VirtualKey == VirtualKey.Up))
{
MoveUp();
}
else if ((args.EventType == CoreAcceleratorKeyEventType.SystemKeyDown
|| args.EventType == CoreAcceleratorKeyEventType.KeyDown)
&& (args.VirtualKey == VirtualKey.Down))
{
MoveDown();
}
};
}
private void MoveUp()
{
// this part is up to you
throw new NotImplementedException();
}
private void MoveDown()
{
// this part is up to you
throw new NotImplementedException();
}
Best of luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With