How to launch RoutedCommand on application level in multiple windows pattern?

杀马特。学长 韩版系。学妹 提交于 2019-12-13 13:42:54

问题


I have a multiple windows in an application, for instance, window1, window2 and window3.

one RoutedCommand (with KeyGesture F11) was binded in window1. How to launch that routed command by pressing F11, while window2 had input focus ?

In WinForm application, i use MessageFilter to detect F11, but in WPF, how to do that ?


回答1:


You can use CommandManager.RegisterClassCommandBinding to hook up a handler to every Window application wide. This will be continue working for the rest of your application run so it usually makes sense to put it in App.xaml.cs but you could put it anywhere.

CommandManager.RegisterClassCommandBinding(typeof(Window), new CommandBinding(ApplicationCommands.Cut, CutExecuted));


来源:https://stackoverflow.com/questions/3191143/how-to-launch-routedcommand-on-application-level-in-multiple-windows-pattern

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!