-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MenuItem HotKey only works after the menu item has been displayed at least once. #2441
Comments
I don't think that these hotkeys should work when the menu isn't open (focused). What you want are global hotkeys(global commands). |
If that would be the desired behavior, I would expect that the hotkeys would stop working if the menu is closed again. But they keep working even when the menu is closed again. |
I think unless you change focus the menu still listens to input gestures. There are plans for a global menu. That should probably always listen to input gestures. |
I've ran another test to see what happens if the focus is changed. After opening the menu once it doesn't matter what is focused, the hotkey still works. Even after switching to different pages and while typing inside a TextBox. My guess is that it only stops working if nothing is focused at all, but I didn't find a way to test that in the Control Gallery. |
Additionally I've found that if you press the Save command in the menu, and then press |
This appears to happen because when using bindings to create the I notice that WPF does not have I'll need to have a bit more of a think about potential fixes to this. |
@kekekeks is currently refactoring I think the only solution is to remove |
Instead of InputBindings in might be good to look at the 'updated' concept of KeyboardAccelerator from UWP. https://docs.microsoft.com/en-us/windows/uwp/design/input/keyboard-accelerators Oh, and then there is gestures for special touch input :) |
A workaround is to use KeyBindings on the window, if anyone finds this thread in the future: <Window.KeyBindings>
<KeyBinding Gesture="Ctrl+O" Command="{Binding OpenCommand}" />
</Window.KeyBindings> |
I use the following method, which also seems to work, and which doesn't require duplicating the keyboard shortcut descriptions: In MainWindow.xaml:
In MainWindow.xaml.cs:
This solution assumes that the |
It looks like this is the same issue which was fixed in #290.
If the
HotKey
property of aMenuItem
is set, it will not work until the user has opened the menu which contains thatMenuItem
.To reproduce the bug simply add the following changes to the Menu sample in the
ControlCatalog
.In
MenuItemViewModel.cs
In
MenuPage.xaml
:In
MenuPageViewModel.cs
With these changes, run the ControlCatalog.Desktop project, and go to the Menu page. Press
Ctrl+S
and notice that nothing will be printed in the output. Open the menu which contains the Save command, and pressCtrl+S
again. This time it will printSave
in the output.The text was updated successfully, but these errors were encountered: