HEUREKA!
我有同样的问题,但与Windows 8.1。我花了2天才找到解决方案。这是愚蠢的SwapChainPanel,因为该类不从Control类继承,所以它不能处理键盘事件,因此无法集中注意力。
解决方案是HERE也就是说,您必须放置一个继承自Control类的XAML元素,例如Button来处理事件。我的XAML文件是这样的:
<SwapChainPanel x:Name="_swapChainPanel"
Loaded="_swapChainPanel_Loaded"
KeyDown="_swapChainPanel_KeyDown">
<Button x:Name="_swapChainButton"
Content="Button"
HorizontalAlignment="Left"
Height="0"
VerticalAlignment="Top"
Width="0"
KeyDown="_swapChainButton_KeyDown">
</Button>
</SwapChainPanel>
在XAML.cs我处理的事件是这样的:
private void _swapChainButton_KeyDown(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e)
{
e.Handled = false; //This will pass the event to its parent, which is the _swapChainPanel
}
private void _swapChainPanel_KeyDown(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e)
{
game.KeyboardEvent();
}
在的KeyboardEvent()方法,我把,如果事情......你有使用代码手动使按钮处于焦点状态。 “_swapChainButton.Focus(FocusState.Programmatic);”
但是最后,它对我来说并不好,它太慢了。它有延迟。 :/
对不起,我迟到发表评论,但这个工作完全正常。谢谢 :) – user1776562