如何在多个Windows模式的应用程序级别启动RoutedCommand? [英] How to launch RoutedCommand on application level in multiple windows pattern?

查看:72
本文介绍了如何在多个Windows模式的应用程序级别启动RoutedCommand?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个应用程序中有多个窗口,例如window1,window2和window3.

在window1中绑定了一个RoutedCommand(带有KeyGesture F11). 在window2具有输入焦点的情况下,如何通过按F11键来启动该路由命令?

在WinForm应用程序中,我使用MessageFilter来检测F11,但是在WPF中,该怎么做?

解决方案

您可以使用CommandManager.RegisterClassCommandBinding将处理程序连接到每个Window应用程序.在其余应用程序运行时,它将继续工作,因此通常将其放在App.xaml.cs中是有意义的,但是您可以将其放置在任何地方.

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

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 ?

解决方案

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));

这篇关于如何在多个Windows模式的应用程序级别启动RoutedCommand?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆