Keyboard accelerator stops working in UWP app

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-04 06:32:12

问题


I'm trying to add a keyboard accelerator to a CommandBar menu item in a UWP app. This works fine when the app starts up, but after I open the overflow menu for the first time, the accelerator stops working. This doesn't appear to happen with primary commands (outside the menu), only secondary commands inside the overflow menu. Also, the menu item still works fine when clicked.

XAML:

<CommandBar>
    <CommandBar.SecondaryCommands>
        <AppBarButton Label="Test" Click="AppBarButton_Click">
            <AppBarButton.KeyboardAccelerators>
                <KeyboardAccelerator Key="A" Modifiers="Control" />
            </AppBarButton.KeyboardAccelerators>
        </AppBarButton>
    </CommandBar.SecondaryCommands>
</CommandBar>

Code behind:

private void AppBarButton_Click(object sender, RoutedEventArgs e)
{
    System.Diagnostics.Debug.WriteLine("test clicked");
}

Am I missing something here or is this a bug in UWP?

Edit: I did some more testing and I'm fairly convinced that this is either a design flaw or a bug. If I make the button a primary command, the accelerator works while the button is visible, but if I resize the window so that it moves to the overflow menu, the accelerator stops working.

来源:https://stackoverflow.com/questions/53735503/keyboard-accelerator-stops-working-in-uwp-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!