tou*_*bsb 0 c# xaml keydown eventhandler uwp
在我的uwp应用程序中,我只是添加了一个新页面并导航到该页面,并且该页面上没有任何内容仅是默认网格。但是我试图接收没有任何按键触发的按键事件。我还把keydown放到了xaml的网格上,并放到了后面代码中的页面上,但是我仍然没有断点,但仍然没有激活。
a
<Grid KeyDown="VideoPageKeyDown">
</Grid>
Run Code Online (Sandbox Code Playgroud)
背后的代码
public sealed partial class VideoPlay : Page
{
public VideoPlay()
{
this.InitializeComponent();
KeyDown += VideoPageKeyDown;
}
private void VideoPageKeyDown(object sender, KeyRoutedEventArgs e)
{
if (e.Key == Windows.System.VirtualKey.GamepadDPadDown || e.Key == Windows.System.VirtualKey.GamepadLeftThumbstickDown)
{
//VideoMenuGrid.Visibility = Visibility.Visible;
//await VideoMenuGrid.Offset(200f, 0f, 1000, 0).StartAsync();
}
else if (e.Key == Windows.System.VirtualKey.GamepadDPadUp || e.Key == Windows.System.VirtualKey.GamepadLeftThumbstickUp)
{
//await VideoMenuGrid.Offset(0f, 0f, 1000, 0).StartAsync();
//VideoMenuGrid.Visibility = Visibility.Collapsed;
}
}
}
Run Code Online (Sandbox Code Playgroud)
诸如网格之类的无法获得焦点的控件将不会直接接收该事件。如果在其顶部还有另一个控件,则可能会将事件传递到网格,因为它是路由事件。您可以改用coreWindow keyDown事件。
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 args)
{
//todo
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
966 次 |
| 最近记录: |