in my uwp app I just added a new page and navigated to it, and I have nothing on that page just the default grid. but I am trying to recieve keydown events which is not firing up by any key at all. I have also put keydown to the grid on xaml and to the page in code behind, but it is still not firing up I have assured that with break points.
xaml
<Grid KeyDown="VideoPageKeyDown">
</Grid>
code behind
public sealed partial class VideoPlay : Page
{
public VideoPlay()
{
this.InitializeComponent();
KeyDown += VideoPageKeyDown;
}
private void VideoPageKeyDown(object sender, KeyRoutedEventArgs e)
{
if (e.Key == VirtualKey.GamepadDPadDown
|| e.Key == VirtualKey.GamepadLeftThumbstickDown)
{
//VideoMenuGrid.Visibility = Visibility.Visible;
//await VideoMenuGrid.Offset(200f, 0f, 1000, 0).StartAsync();
}
else if (e.Key == VirtualKey.GamepadDPadUp
|| e.Key == VirtualKey.GamepadLeftThumbstickUp)
{
//await VideoMenuGrid.Offset(0f, 0f, 1000, 0).StartAsync();
//VideoMenuGrid.Visibility = Visibility.Collapsed;
}
}
}
Controls like the grid that do not get focus will not receive the event directly. If there is another control on top of it might pass the event to the grid because it is an routed event. Thy using the coreWindow keyDown event instead.
public sealed partial class VideoPlay : Page
{
public VideoPlay()
{
this.InitializeComponent();
//Add this line
Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;
}
void CoreWindow_KeyDown(Windows.UI.Core.CoreWindow sender, Windows.UI.Core.KeyEventArgs e)
{
//todo
}
}
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