如何获取会触发路由命令的输入绑定?

时间:2022-11-27 19:39:25

I have a menuitem which have a command assigned to it (MyCommands.Indent) and two text areas, both having an input binding triggering MyCommands.Indent. The hard part is that input bindings have different gestures and I would like these gestures to change in MenuItem.

我有一个menuitem,它有一个命令(MyCommands.Indent)和两个文本区域,都有一个输入绑定触发MyCommands.Indent。困难的部分是输入绑定具有不同的手势,我希望这些手势在MenuItem中更改。

So my question is: How do I get input bindings which would trigger this routed command?

所以我的问题是:如何获得会触发此路由命令的输入绑定?

1 个解决方案

#1


The only way I can see to do specifically what you're asking, is to explore the visual tree to find items with InputBindings to your RoutedCommand... not a very nice thought !

我能看到你要问的唯一方法是探索可视化树,找到带有InputBindings的项目到你的RoutedCommand ......不是一个很好的想法!

But there might be a better approach : what don't you just define the shortcut in the RoutedCommand, using the InputGestures property ? That way you won't be needing the InputBindings anymore...

但是可能有更好的方法:你不是只使用InputGestures属性在RoutedCommand中定义快捷方式?这样你就不再需要InputBindings ......

#1


The only way I can see to do specifically what you're asking, is to explore the visual tree to find items with InputBindings to your RoutedCommand... not a very nice thought !

我能看到你要问的唯一方法是探索可视化树,找到带有InputBindings的项目到你的RoutedCommand ......不是一个很好的想法!

But there might be a better approach : what don't you just define the shortcut in the RoutedCommand, using the InputGestures property ? That way you won't be needing the InputBindings anymore...

但是可能有更好的方法:你不是只使用InputGestures属性在RoutedCommand中定义快捷方式?这样你就不再需要InputBindings ......