Using the keyboard to display a context menu in a data-related WPF TreeView

I have a DataBound (via HierachicTemplates) WPF TreeView that works fine with the mouse, but I want it to be able to control it using the keyboard. I added CommandBindings so that ContextMenu elements can be executed using gestures; for example CTRL + Delete to delete the currently selected item, but I want the Properties key to display a context menu and so that the user can use the cursor keys to navigate it.

I created a CommandBinding and debugged it, but RoutedUIEvent has ContextMenu. I tried to create it from Xmal Resources and it worked, but this is clearly wrong, since everything is disabled.

How to create WPF ContextMenu with which I can navigate from the keyboard?

+3
source share
1 answer

I was able to display the ContextMenu control as follows:

  • listen to your KeyboardEvent (e.g. property key)
  • in the handler, get your control (by name or by any method)
  • when you have control, just do: myControl.ContextMenu.IsOpen = true;

hope this helps.

+2
source

Source: https://habr.com/ru/post/1781120/


All Articles