Search code examples
c#wpfxamlmenuitemkey-bindings

Is it possible to toggle a menu from keyboard input?


I'm building a dashboard'ish application for a special purpose hardware that has physical buttons that are bound to F1-F10, Up, Down, Backspace, Enter. The application consists of a few views (implemented using the MVVM-pattern) and most of the user interaction are done with menus that are aligned near the physical buttons. I'm trying to toggle the menu state by pressing the F-keys but I just can't get the bloody thing to work!

I've (successfully, kinda) tried an alternative solution that catches the F-keys and sends them as regular numbers 1-10 and mapping Alt+[1-10] to the meny using Accesskey. That is not an optimal solution though since I have to keep track of if the menu looses focus (the user can also navigate with a touch screen). Besides that I also have try and hide the accesskey-text from the menuitem-header (since it seems impossible to just make it invisible).


Solution

  • Honestly, I'd just make a regular Window and hide/show it as appropriate - just have an ItemsControl whose DataTemplate is a MenuItem. Menus are managed in the standard "menu" way, so it'll be hard to override it and manually manage the hidden/shown state.