Using the Keyboard to show a context menu in a data bound WPF TreeView
I've got a DataBound (via HierachicTemplates) WPF TreeView that works fine with the mouse, but I want it to able to drive it with the keyboard. I've added CommandBindings so that ContextMenu items can be executed via 'gestures'; li开发者_开发问答ke CTRL+Delete to remove the currently selected item, but what I want is for the 'Properties' key to display the context menu and for the user to be able to use the cursor keys to navigate it.
I created a CommandBinding and debugged it but the RoutedUIEvent does have a ContextMenu. I tried creating it from the Xmal Resources and that worked but it is clearly not correct as everything is disabled.
How do I create a WPF ContextMenu that I can navigate with the keyboard?
I managed to display an control's ContextMenu like this :
- listen for your KeyboardEvent (property key down for instance)
- in the handler, get your control (by name or whatever method)
- when you have your control, simply do :
myControl.ContextMenu.IsOpen = true;
hope it helps.
精彩评论