我正在尝试将键盘加速器添加到 UWP 应用程序中的 CommandBar 菜单项。当应用程序启动时,这工作正常,但在我第一次打开溢出菜单后,加速器停止工作。这似乎不会发生在主要命令(菜单之外)上,只有溢出菜单内的辅助命令才会发生。此外,单击菜单项时仍然可以正常工作。
XAML:
<CommandBar>
<CommandBar.SecondaryCommands>
<AppBarButton Label="Test" Click="AppBarButton_Click">
<AppBarButton.KeyboardAccelerators>
<KeyboardAccelerator Key="A" Modifiers="Control" />
</AppBarButton.KeyboardAccelerators>
</AppBarButton>
</CommandBar.SecondaryCommands>
</CommandBar>
背后代码:
private void AppBarButton_Click(object sender, RoutedEventArgs e)
{
System.Diagnostics.Debug.WriteLine("test clicked");
}
我在这里遗漏了一些东西还是这是 UWP 中的错误?
Edit:我做了更多测试,并且相当确信这要么是设计缺陷,要么是错误。如果我将按钮设为主要命令,则加速器会在按钮可见时工作,但如果我调整窗口大小以使其移至溢出菜单,则加速器将停止工作。
由于此错误尚未得到解决,因此存在解决方法。
使用相同的单击事件和相同的键盘加速器创建无空间按钮(它们必须可见)。您无需担心双重射击。它只会触发第一个。
<Grid Height="0" Width="0" Opacity="0">
<Button IsTabStop="False" Click="AppBarButton_Click">
<Button.KeyboardAccelerators>
<KeyboardAccelerator Key="A" Modifiers="Control" />
</Button.KeyboardAccelerators>
</Button>
</Grid>
<CommandBar>
<CommandBar.SecondaryCommands>
<AppBarButton Label="Test" Click="AppBarButton_Click">
<AppBarButton.KeyboardAccelerators>
<KeyboardAccelerator Key="A" Modifiers="Control" />
</AppBarButton.KeyboardAccelerators>
</AppBarButton>
</CommandBar.SecondaryCommands>
</CommandBar>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)