Xaml 为什么XYFocusKeyboardNavigation不工作?
我想防止在CommandBar控件中处理键盘箭头的onKeyDown事件 我禁用了XYFocusKeyboardNavigation,但它不起作用-我仍然能够使用“左”/“右”箭头在按钮之间导航。为什么Xaml 为什么XYFocusKeyboardNavigation不工作?,xaml,uwp,Xaml,Uwp,我想防止在CommandBar控件中处理键盘箭头的onKeyDown事件 我禁用了XYFocusKeyboardNavigation,但它不起作用-我仍然能够使用“左”/“右”箭头在按钮之间导航。为什么 <CommandBar XYFocusKeyboardNavigation="Disabled"> <AppBarButton Label="menu"> <AppBarButton.Icon>
<CommandBar XYFocusKeyboardNavigation="Disabled">
<AppBarButton Label="menu">
<AppBarButton.Icon>
<BitmapIcon UriSource="/Help/home.png"/>
</AppBarButton.Icon>
</AppBarButton>
<AppBarButton x:Name="hideLeavesButton" Label="hide leaves" Click="HideLeavesButton_Click">
<AppBarButton.Icon>
<BitmapIcon UriSource="/Help/hideLeaves.png"/>
</AppBarButton.Icon>
</AppBarButton>
</CommandBar>
为什么XYFocusKeyboardNavigation不工作
这看起来是一个bug,我将报告它,目前我们有一个解决方案,防止处理键盘箭头的onKeyDown事件。有关详细信息,请参考以下内容
Window.Current.Content.PreviewKeyDown += Content_PreviewKeyDown;
private void Content_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
{
if (e.Key == VirtualKey.Left | e.Key == VirtualKey.Right | e.Key == VirtualKey.Up | e.Key == VirtualKey.Down)
{
e.Handled = true;
}
else
{
e.Handled = false;
}
}
它看起来确实像一个bug,我也遇到了同样的问题。另一种简单的方法是将
IsTabStop=“false”
设置到每个按钮。不幸的是,对于复杂的用户界面来说,这比它应该的复杂得多谢谢。不幸的是,它阻止父控件hanks处理事件。我认为应该是:IsTabStop=“false”